home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / ab20 / ab20_archive / text / cmanual.lzh / ACM3.lzh / LowLevelGraphics / LowLevelGraphics.doc < prev    next >
Text File  |  1991-01-27  |  93KB  |  3,049 lines

  1. 12    LOW LEVEL GRAPHICS ROUTINES
  2.  
  3. 12.1  INTRODUCTION
  4.  
  5. In this chapter will we look at Amiga's low level graphics
  6. routines. As you saw in chapter 3 (GRAPHICS) the Amiga offers
  7. two different levels of graphics support. You can either use
  8. the high level graphics routines that use structures in order
  9. to give your program flexibility, or you can use the low level
  10. graphics routines that give your program total control over
  11. the graphics system. We will in this chapter look at the low
  12. level graphics routines.
  13.  
  14. The low level graphics routines can be divided into two
  15. sections. The first section is about creating a display. We
  16. here describe how to chose the screen resolution, how many
  17. colours, interlaced or non interlaced, the size of the viewports
  18. etc. In the second section is about all different types of
  19. drawing tools the Amiga offers. We will here describe how to
  20. draw a single dot, lines, polygons, how to change colours, how
  21. to use patterns and masks, and look at different types of
  22. filling routines etc.
  23.  
  24.  
  25.  
  26. 12.2  CREATE A DISPLAY
  27.  
  28. We will now take a look at how to create a display. However,
  29. before we start with that it is best to give some general
  30. information about computers and graphics.
  31.  
  32.  
  33.  
  34. 12.2.1  GENERAL INFORMATION
  35.  
  36. We will here describe how a picture is generated on a display.
  37. We will also look at some special display modes such as
  38. "Interlaced", high respectively low resolution etc. Finally we
  39. will discuss what a pixel is and what Bitplanes are used for.
  40.  
  41.  
  42.  
  43. 12.2.1.1  HOW A MONITOR/TV WORK
  44.  
  45. The video picture that is displayed on a monitor/TV is actually
  46. "painted" by a small video beam. The video beam starts at the
  47. top left corner of the screen. While it is moved to the right
  48. the intensity of the beam is varied so lighter and darker spots
  49. are drawn. Once the beam has reached the right side of the
  50. screen, it is moved back to the left side and positioned a bit
  51. further down. It is then moved once again to the right side, and
  52. so on.
  53.  
  54. On an American display (NTSC) the beam is moved from the left to
  55. the right 262 times (On an European PAL display 312 times). The
  56. beam has now reached the bottom of the screen and is moved back
  57. to the top left corner where the process is repeated. The
  58. screen is painted like this 60 times a second on a NTSC monitor,
  59. and 50 times a second on a PAL monitor. 
  60.  
  61. The video picture on an American (NTSC) monitor:
  62.  
  63.     1  ->---->----> |
  64.     2  ->---->----> |
  65.     3  ->---->----> |
  66.     |  and so on... |
  67.   261  ->---->----> |
  68.   262  ->---->----> V
  69.  
  70. As you can see you can have a display that is up to 262 (312)
  71. lines tall, but normally you do not use the very first and last
  72. lines since they can be hard to see. You are recommended to use
  73. a display of maximum 200 (256 PAL) lines. However, if you want
  74. to use special video effects, or make the screen to cover the
  75. whole display, all 262 (312) lines can be used. This special
  76. effect is normally referred as "Overscan".
  77.  
  78.  
  79.  
  80. 12.2.1.2  INTERLACED
  81.  
  82. A full sized normal American (NTSC) display is 200 lines tall
  83. (PAL 256 lines). However, the Amiga has a unique feature that
  84. can double the amount of lines on the same display to 400 
  85. (PAL 512). This special mode is called Interlace.
  86.  
  87. The first time the video beam is moved over the screen, all odd
  88. lines are drawn (1, 3, 5, 7 ... 397, 399), and the second time
  89. all even lines are drawn (2, 4, 6, 8 .. 398, 400). This special
  90. mode can cause the screen to "flicker" especially if the contrast
  91. is high. This is because all odd lines are drawn 30 (PAL 25)
  92. times a second, and all even lines 30 (25) times a second. If
  93. you have a high phosphor screen you will not have any problems,
  94. but on cheap normal monitors the flickering can be very annoying.
  95.  
  96. First time      Second time
  97.      1 -------------
  98.        ------------- 2
  99.      3 -------------
  100.        ------------- 4
  101.      5 -------------
  102.        ------------- 6
  103.      7 -------------
  104.        ------------- 8
  105.        and so on ...  
  106.  
  107.  
  108.  
  109. 12.2.1.3  HIGH AND LOW RESOLUTION
  110.  
  111. There exist two different types of horizontal resolution. Low
  112. resolution gives 320 pixels across each line, and high
  113. resolution doubles it to 640 pixels.
  114.  
  115. There is an important difference between these two display
  116. modes. In low resolution you can have up to 32 colours or
  117. even use HAM or Extra Half Bright (explained later), but in
  118. high resolution you may only use 16 colours or less.  
  119.  
  120. You may even here use the special display mode "Overscan".
  121. The display may then be up to 352 pixels wide in low resolution,
  122. and 704 pixels in high resolution.
  123.  
  124.  
  125.  
  126. 12.2.1.4  PIXELS
  127.  
  128. The display is built up of small dots called "Pixels". As
  129. described above there may be either 320 or 640 pixels across
  130. each line, and 200 or 400 lines (PAL 256 or 512 lines).
  131.  
  132. When you create a display you allocate rectangular memory areas
  133. that are called "Bitplanes". Each bit in that memory area
  134. represent one pixel.
  135.  
  136. A high resolution non interlaced American display, 640 * 200
  137. pixels will need 16,000 bytes of memory for one bitplane.
  138.  
  139. To create a very small screen (8 * 9 pixels) that will display
  140. an "A" the bitplane could look something like this: 
  141.  
  142.   Line  Bitplane 1
  143.   ----------------
  144.      1  00000000
  145.      2  00111100
  146.      3  01000010
  147.      4  01000010
  148.      5  01111110
  149.      6  01000010
  150.      7  01000010
  151.      8  01000010
  152.      9  00000000
  153.  
  154.  
  155.  
  156. 12.2.1.5  COLOURS
  157.  
  158. If you want to use several colours on the screen you need to
  159. use several bitplanes. All bits on the same location in each
  160. bitplane will then represent one pixel. With two bitplanes you
  161. can have four different combinations for every pixel. Three
  162. bitplanes gives eight combinations. Four bitplanes sixteen
  163. combinations, and finally five bitplanes thirty two
  164. combinations.
  165.  
  166. Here is an example. We have reserved memory for two bitplanes
  167. that will build up a very small display of 10 pixels each line,
  168. and four lines.
  169.  
  170.   Line  Bitplane 1  Bitplane 2  Display (Colour)
  171.   ----------------------------------------------
  172.      1  0000000000  0000000000  0000000000
  173.      2  1111111111  0000000000  1111111111
  174.      3  0000000000  1111111111  2222222222
  175.      4  1111111111  1111111111  3333333333
  176.  
  177. The first line is made up of ten pixels in colour 0  (00[b]=0[d])
  178. The second line is made up of ten pixels in colour 1 (01[b]=1[d])
  179. The third line is made up of ten pixels in colour 2  (10[b]=2[d])
  180. The fourth line is made up of ten pixels in colour 3 (11[b]=3[d])
  181.  
  182. The more bitplanes you have the more colours you can display.
  183. However, since you need more bitplanes you would need to
  184. allocate more memory.
  185.  
  186.   Bitplanes  Colours
  187.   ------------------
  188.           1        2
  189.           2        4
  190.           3        8
  191.           4       16
  192.           5       32
  193.  
  194.  
  195.  
  196. 12.2.2  DISPLAY ELEMENTS
  197.  
  198. 12.2.2.1  RASTER
  199.  
  200. The are which you may draw on is called Raster. It consists of
  201. several BitMaps on top of each other. The more Bitmaps the more
  202. colours may be used at the same time. The Raster may be up to
  203. 1024 pixels wide (RWidth), and 1024 pixels high (RHeight).
  204.  
  205. The part of the Raster that will be displayed is called
  206. ViewPort. A structure called RasInfo contains the RxOffset
  207. and RyOffset values which determines what part of the Raster
  208. should be displayed in the ViewPort. The ViewPort is DWide
  209. pixels wide, and DHeight pixels high. (Simple, isn't it?)
  210.  
  211.   RASTER:
  212.  
  213.     <- RxOffset ->
  214.     --------------------------- A
  215.     |          D   ViewPort   | | RyOffset
  216.     |          H ------------ | V
  217.   R |          e |XXXXXXXXXX| |
  218.   H |          i |XXXXXXXXXX|-+-- Display this part
  219.   e |          g |XXXXXXXXXX| |
  220.   i |          h ------------ |
  221.   g |          t    DWidth    |
  222.   h |                         |
  223.   t |                         | 
  224.     |                         |
  225.     |                         |
  226.     ---------------------------
  227.             RWidth         
  228.  
  229.  
  230.  
  231. 12.2.2.2  VIEW
  232.  
  233. The video display has an are in which you may put one or
  234. more ViewPorts. That area is called View, and the DxOffset
  235. and DyOffset values in the View structure determines where
  236. on the video display the View should be positioned.
  237.  
  238. You can set the DxOffset and DyOffset to negative values. The
  239. View will then be more to the left and higher up than normal.
  240. The top left part of the drawing can be hard to see and this
  241. mode is therefore not recommended for business programs.
  242. However, if you write games or video programs this special
  243. display mode can be very useful.
  244.  
  245.   VIEW:
  246.  
  247.   <--> DxOffset
  248.   ------------------------ A
  249.   |    VIDEO  DISPLAY    | | DyOffset
  250.   |  ------------------  | V
  251.   |  |                |  |
  252.   |  |                |  |
  253.   |  |                |  |
  254.   |  |      VIEW      |  |
  255.   |  |                |  |
  256.   |  |                |  |
  257.   |  |                |  |
  258.   |  ------------------  |
  259.   |                      |
  260.   ------------------------
  261.  
  262.  
  263.  
  264. 12.2.2.3  VIEWPORT
  265.  
  266. The View may, as said above, contain one or more ViewPorts. The
  267. DxOffset and DyOffset values in the ViewPort structure
  268. determines where on the View the ViewPort should be positioned.
  269.  
  270.   <--> DxOffset
  271.   ------------------ A
  272.   |      VIEW      | | DyOffset
  273.   |  ------------  | V
  274.   |  |          |  |
  275.   |  | VIEWPORT |  |
  276.   |  |          |  |
  277.   |  ------------  |
  278.   |                |
  279.   ------------------
  280.  
  281.  
  282. There are some important restriction on how you may place the
  283. ViewPorts. The ViewPorts must be placed under each other, with
  284. at least one or more lines apart. While the video beam has
  285. drawn the last line of one ViewPort, the Amiga needs some time
  286. to adjust to the new resolution etc in the next ViewPort. While
  287. the Amiga is working with the next screen, the video beam will
  288. have travelled down at least one line (maybe more).
  289.  
  290.    The View (The Display)
  291.   ------------------------
  292.   |  Background colour   |
  293.   | --------------       |
  294.   | | ViewPort 1 |       |
  295.   | |            |       |
  296.   | --------------       | ==> At least one line must
  297.   |       -------------- |     separate the ViewPorts.
  298.   |       | ViewPort 2 | |
  299.   |       -------------- |
  300.   ------------------------
  301.  
  302. The are around the ViewPorts are filled with the ViewPort's
  303. background colour.
  304.  
  305. Here are three examples:
  306.  
  307.   Correct! The ViewPorts do
  308.   not overlap each other,
  309.   and there is some space
  310.   between them:
  311.   ------------------------
  312.   | -------------------- |
  313.   | |                  | |
  314.   | -------------------- |
  315.   |    -------------     |
  316.   |    |           |     |
  317.   |    -------------     |
  318.   | -------------------- |
  319.   | |                  | |
  320.   | -------------------- |
  321.   ------------------------
  322.  
  323.   Incorrect! The ViewPorts    Incorrect! There must be
  324.   must be placed under each   some space between ViewPorts.
  325.   other, not beside each      (At least one line, maybe
  326.   other.                      more.)
  327.   ------------------------    ------------------------
  328.   | ---------  --------- |    | -------------------- |
  329.   | |       |  |       | |    | |                  | |
  330.   | |       |  |       | |    | |                  | |
  331.   | |       |  |       | |    | |                  | |
  332.   | |       |  |       | |    | -------------------- |
  333.   | |       |  |       | |    | |                  | |
  334.   | |       |  |       | |    | |                  | |
  335.   | |       |  |       | |    | |                  | |
  336.   | ---------  --------- |    | -------------------- |
  337.   ------------------------    ------------------------
  338.  
  339.  
  340.  
  341. 12.2.2.4  BITMAP
  342.  
  343. The area on which you may draw on is, as said above, called
  344. Raster. The Raster itself is built up of one or more BitMaps. 
  345. A BitMap is a rectangular memory area. Each bit in that area
  346. represent one small dot (pixel). You may use several BitMaps
  347. which means that each dot is built up of several bits (one bit
  348. for every BitMap), and the binary value of these bits
  349. determines what colour should be used.
  350.  
  351.    BitMap 0    BitMap 1    BitMap 2        Colour
  352.   -------------------------------------------------
  353.   0000011111  0000000000  0000000000  |  0000011111
  354.   0000011111  1111111111  0000000000  |  2222233333
  355.   0000011111  0000000000  1111111111  |  4444455555
  356.   0000011111  1111100000  1111111111  |  6666677777
  357.  
  358.  
  359.      B I N A R Y   T O   D E C I M A L
  360.   ---------------------------------------
  361.   | Binary  Decimal  |  Binary  Decimal |
  362.   |------------------+------------------|
  363.   | 00000         0  |  10000        16 |
  364.   | 00001         1  |  10001        17 |
  365.   | 00010         2  |  10010        18 |
  366.   | 00011         3  |  10011        19 |
  367.   |                  |                  |
  368.   | 00100         4  |  10100        20 |
  369.   | 00101         5  |  10101        21 |
  370.   | 00110         6  |  10110        22 |
  371.   | 00111         7  |  10111        23 |
  372.   |                  |                  |
  373.   | 01000         8  |  11000        24 |
  374.   | 01001         9  |  11001        25 |
  375.   | 01010        10  |  11010        26 |
  376.   | 01011        11  |  11011        27 |
  377.   |                  |                  |
  378.   | 01000        12  |  11000        28 |
  379.   | 01101        13  |  11101        29 |
  380.   | 01110        14  |  11110        30 |
  381.   | 01111        15  |  11111        31 |
  382.   ---------------------------------------
  383.  
  384. The more BitMaps the more colours can be used. The Amiga allows
  385. you to have up to six bitplanes with some restrictions:
  386.  
  387.   BitMaps  Colours  Limitations
  388.   -------------------------------------------------------------
  389.         1        2
  390.         2        4
  391.         3        8
  392.         4       16  Single playfield
  393.         5       32         - " -     low resolution
  394.         6       64         - " -          - " -     Half bright
  395.         6     4096         -"-            - " -     HAM
  396.  
  397.  
  398.  
  399. 12.2.3  CREATE A DISPLAY
  400.  
  401. When you create a display you first have to declare and
  402. initialize some important structures. These structures are:
  403.   1. View structure
  404.   2. ViewPort structure
  405.   3. ColourMap structure
  406.   4. BitMap structure
  407.   5. RasInfo structure
  408.  
  409. Once these structures are initialized you call three functions
  410. [MakeVPort(), MrgCop() and LoadView() ] and your new display is
  411. on.
  412.  
  413.  
  414.  
  415. 12.2.3.1  VIEW
  416.  
  417. A View can consist of one or more ViewPorts. You can also have
  418. several Views at the same time in the Amiga's memory, but only
  419. one View can be showed at one time. The advantage of several
  420. Views is that you can show the user one picture (one View)
  421. while the other picture is drawn (in the other View.)
  422.  
  423. The View itself has some important variables that determines
  424. the position of the View, if the view should be interlaced or
  425. not, and pointers to the first ViewPort etc.
  426.  
  427.  
  428.  
  429. 12.2.3.1.1  VIEW STRUCTURE
  430.  
  431. The View structure look like this: [Defined in file:
  432. "view.h"]
  433.  
  434. struct View
  435. {
  436.   struct ViewPort *ViewPort;
  437.   struct cprlist *LOFCprList;
  438.   struct cprlist *SHFCprList;
  439.   short DyOffset, DxOffset;
  440.   UWORD Modes;
  441. };
  442.  
  443. ViewPort:   Pointer to the first ViewPort in the display.
  444.  
  445. LOFCprList: Pointer to a cprlist structure that is used
  446.             by the Copper (explained later).
  447.  
  448. SHFCprList: Pointer to a cprlist structure that is used
  449.             by the Copper if the structure is interlaced.
  450.             (If the display is interlaced, both LOFCprList
  451.             and SHFCprList is used.)
  452.  
  453. DyOffset:   Y position of the whole display.
  454.  
  455. DxOffset:   X position of the whole display.
  456.  
  457. Modes:      If the display should be interlaced set the flag
  458.             LACE. If the display should be merged together
  459.             with a external video signal with help of a Genlock
  460.             set the flag GENLOCK_VIDEO.
  461.  
  462.  
  463.  
  464. 12.2.3.1.2  PREPARE A VIEW STRUCTURE
  465.  
  466. After you have declared a View structure you have to prepare
  467. it. To do it you call the InitView() function with a pointer
  468. to the View structure as the only parameter:
  469.  
  470. struct View my_view;  /* Declare the View structure. */
  471.  
  472. InitView( &my_view ); /* Prepare it. */
  473.  
  474. If you want to position you View somewhere on the display you
  475. need to set the DxOffset and DyOffset accordingly. For example:
  476. my_view.DxOffset = 20; /* 20 pixels out. */
  477. my_view.DyOffset = 50; /* 50 lines down. */
  478.  
  479. If you want to use an interlaced display you should also set
  480. the "LACE" flag. For example: my_view.Modes = LACE;
  481.  
  482.  
  483.  
  484. 12.2.3.2  VIEWPORTS
  485.  
  486. As said above, each View can consists of one or more ViewPorts.
  487. Each ViewPort can have its own resolution, number of colours and
  488. size.
  489.  
  490.  
  491.  
  492. 12.2.3.2.1  VIEWPORT STRUCTURE
  493.  
  494. The ViewPort structure look like this: [Defined in file:
  495. "view.h"]
  496.  
  497. struct ViewPort
  498. {
  499.   struct ViewPort *Next;
  500.   struct ColorMap *ColorMap;
  501.   struct CopList *DspIns;
  502.   struct CopList *SprIns;
  503.   struct CopList *ClrIns;
  504.   struct UCopList *UCopIns;
  505.   SHORT DWidth, DHeight;
  506.   SHORT DxOffset, DyOffset;
  507.   UWORD Modes;
  508.   UBYTE SpritePriorities;
  509.   UBYTE reserved;
  510.   struct RasInfo *RasInfo;
  511. };
  512.  
  513. Next:             Pointer to the next ViewPort in the View if
  514.                   there exist more, else NULL.
  515.  
  516. ColorMap:         Pointer to a ColorMap structure used for this
  517.                   ViewPort. (See below for more information
  518.                   about the ColorMap structure.
  519.  
  520. DspIns:           Used by the Copper.
  521.  
  522. SprIns:           Special colour instructions for sprites.
  523.  
  524. ClrIns:           Special colour instructions for sprites.
  525.  
  526. UCopIns:          Used by the Copper.
  527.  
  528. DWidth:           Horizontal size of the ViewPort.
  529.  
  530. DHeight:          Vertical size of the ViewPort.
  531.  
  532. DxOffset:         X position of the ViewPort inside the View.
  533.  
  534. DyOffset:         Y position of the ViewPort inside the View.
  535.  
  536. Modes:            This ViewPort's display mode. Following flags
  537.                   can be used:
  538.                   
  539.                   HIRES:           Set this flag if you want
  540.                                    to use a high resolution
  541.                                    ViewPort, else low resolution
  542.                                    will be used.
  543.  
  544.                   LACE:            Set this flag if you want
  545.                                    the ViewPort to be
  546.                                    interlaced, else it will
  547.                                    be non interlaced.
  548.  
  549.                   SPRITES:         Set this flag if you will
  550.                                    use sprites in this ViewPort.
  551.  
  552.                   HAM:             Set this flag if you want to
  553.                                    use the special display mode
  554.                                    "Hold And Modify". The
  555.                                    display must be in low
  556.                                    resolution, and use six
  557.                                    bitplanes. Allows all 4096
  558.                                    colours to be displayed at
  559.                                    the same time.
  560.  
  561.                   EXTRA_HALFBRITE: Set this flag if you want to
  562.                                    use the special display mode
  563.                                    "Extra Half Bright". The
  564.                                    display must be in low
  565.                                    resolution, and use six
  566.                                    bitplanes. Allows you to use
  567.                                    64 colours.
  568.  
  569.                   DUALPF:          Set this flag if you want to
  570.                                    use dual playfields.
  571.  
  572.                   PFBA:            Set this flag if you want
  573.                                    that playfield 1 should be
  574.                                    behind playfield 2. If this
  575.                                    flag is not set, the
  576.                                    priorities will be reversed.
  577.  
  578.                   GENLOCK_VIDEO:   Set this flag if the display
  579.                                    should be mixed together with
  580.                                    a video signal with help of a
  581.                                    Genlock.
  582.                   
  583.                   Note! You can combine several of these modes
  584.                   if you like. Just remember to put a "|" between
  585.                   each flag. For example: To create a high
  586.                   resolution interlaced ViewPort you set the
  587.                   mode to "HIRES|LACE". 
  588.  
  589. SpritePriorities: The priority of this ViewPort's sprites.
  590.  
  591. reserved:         Which sprites are reserved, and can not be
  592.                   used. (See chapter SPRITES and VSPRITES for
  593.                   more information.)
  594.  
  595. RasInfo:          Pointer to a RasInfo structure.
  596.  
  597.  
  598.  
  599. 12.2.3.2.2  PREPARE A VIEWPORT STRUCTURE
  600.  
  601. After you have declared a ViewPort structure you have to
  602. prepare it. (Same as with all View structures.) To do it you
  603. call the InitVPort() function with a pointer to the ViewPort
  604. structure as the only parameter:
  605.  
  606. /* Declare the View structure: */
  607. struct ViewPort my_view_port;
  608.  
  609. /* Prepare it: */
  610. InitVPort( &my_view_port );
  611.  
  612.  
  613. After you have prepared it you set the desired values: (An example)
  614.  
  615. my_view_port.Next = NULL;            If we have several ViewPorts
  616.                                      in the same View we link
  617.                                      them together, else NULL.
  618.  
  619. my_view_port.DWidth = WIDTH;         Set the desired width.
  620. my_view_port.DHeight = HEIGHT;       Set the desired height.
  621.  
  622. my_view_port.DxOffset = 0;           X and Y position of the
  623. my_view_port.DyOffset = 0;           ViewPort in the View.
  624.  
  625. my_view_port.Modes = HIRES|LACE;     Set desired flags. (Eg
  626.                                      high resolution interlace)
  627.  
  628. my_view_port.RasInfo = &my_ras_info; Pointer to this ViewPort's
  629.                                      RasInfo.
  630.  
  631.  
  632.  
  633. 12.2.3.3  COLORMAP
  634.  
  635. Each ViewPort has a its own lists of colours. They are stored
  636. in a ColorMap structure which contains information like: how
  637. many colours this display use, what colours, and each colours
  638. individual RGB values. (Red + Green + Blue intensity)
  639.  
  640.  
  641.  
  642. 12.2.3.3.1  COLORMAP STRUCTURE
  643.  
  644. The ColorMap structure look like this: [Defined in file:
  645. "view.h"]
  646.  
  647. struct ColorMap
  648. {
  649.   UBYTE Flags;
  650.   UBYTE Type;
  651.   UWORD Count;
  652.   APTR ColorTable;
  653. };
  654.  
  655.  
  656.  
  657. 12.2.3.3.2  DECLARE AND INITIALIZE A COLORMAP STRUCTURE
  658.  
  659. To declare and initialize a ColorMap structure you simply call
  660. the GetColorMap() function. It will take care of everything,
  661. and the only thing you need to tell the function is how many
  662. colours you want to use.
  663.  
  664. Get a colour map, and link it to the ViewPort:
  665.  
  666. my_view_port.ColorMap = GetColorMap( 32 );
  667.  
  668. You should also remember to check if you have got the the colour
  669. map or not. For example:
  670.  
  671. if( my_view_port.ColorMap == NULL )
  672.   clean_up(); /* leave */
  673.  
  674.  
  675.  
  676. 12.2.3.3.3  SET THE RGB VALUES
  677.  
  678. Once you have got your ColorMap structure, you need to set
  679. the RGB (Red, Green, Blue) values for each colour. Each colour
  680. can have a mixture of red, green and blue, on a scale from 0
  681. to 15. Hexadecimal that would be from 0x0 to 0xF.
  682.  
  683. Here are some examples:
  684.  
  685.   RGB value  Colour
  686.   ---------------------
  687.   0xF00      Red
  688.   0x0F0      Green
  689.   0x00F      Blue
  690.   0x600      Dark red
  691.   0x060      Dark green
  692.   0x006      Dark blue
  693.   0xFF0      Yellow
  694.   0x000      Black
  695.   0x444      Dark grey
  696.   0x888      Light grey
  697.   0xFFF      White  
  698.  
  699. Since each RGB values can have sixteen intensities, you can
  700. define up to 16 * 16 * 16 = 4096 different colours. 
  701.  
  702. If you prepare a ColorMap structure to use four colours,
  703. you need to give it a colour table of RGB values.
  704.  
  705. /* 1. Declare a RGB colour table: */ 
  706. UWORD my_color_table[] =
  707. {
  708.   0x000, /* Black */
  709.   0xF00, /* Red */
  710.   0x0F0, /* Green */
  711.   0x00F, /* Blue */
  712. };
  713.  
  714. /* 2. Declare a pointer: */
  715. UWORD *pointer;
  716.  
  717. /* 3. Set the pointer so it points to the colour table: */
  718. pointer = (UWORD *) my_view_port.ColorMap->ColorTable;
  719.  
  720. /* 4. Set the colours: */
  721. for( loop = 0; loop < 4; loop++ )
  722.   *pointer++ = my_color_table[ loop ];
  723.  
  724.  
  725.  
  726. 12.2.3.3.4  DEALLOCATE THE COLOURMAP
  727.  
  728. When your program closes a ViewPort you must remember to
  729. deallocate the memory used for the ColourMap. You deallocate
  730. a ColourMap with help of the FreeColorMap() function:
  731.  
  732. FreeColorMap( my_view_port.ColorMap );
  733.  
  734.  
  735.  
  736. 12.2.3.4  BITMAP
  737.  
  738. The BitMap is, as said above,  a rectangular memory are were
  739. each bit represents one pixel. By combining two or more BitMaps
  740. each pixel is represented by a combination of two or more bits
  741. which determines what colour should be used. A pointer to each
  742. BitMap, information about the size of the BitMaps etc are all
  743. stored in the BitMap structure.
  744.  
  745.  
  746.  
  747. 12.2.3.4.1  BITMAP STRUCTURE
  748.  
  749. The BitMap structure look like this: [Defined in file: "gfx.h"]
  750.  
  751. struct BitMap
  752. {
  753.   UWORD BytesPerRow;
  754.   UWORD Rows;
  755.   UBYTE Flags;
  756.   UBYTE Depth;
  757.   UWORD pad;
  758.   PLANEPTR Planes[ 8 ];
  759. };
  760.  
  761. BytesPerRow: How many bytes are used on every row.
  762.  
  763. Rows:        How many rows there are.
  764.  
  765. Flags:       Special information about the BitMaps (for the
  766.              moment not used.)
  767.  
  768. Depth:       How many BitPlanes.
  769.  
  770. pad:         Extra space.
  771.  
  772. Planes:      A list of eight pointers. (PLANEPTR is a pointer
  773.              to a BitMap.)
  774.  
  775.  
  776.  
  777.  
  778. 12.2.3.4.2  DECLARE AND INITIALIZE A BITMAP STRUCTURE
  779.  
  780. You declare the structure as normal, and initialize it with
  781. help of the function InitBitMap(). You need to give the function
  782. a pointer to your BitMap structure and information about the
  783. size and depth (how many BitPlanes used).
  784.  
  785. Synopsis: InitBitMap( bitmap, depth, width, height );
  786.  
  787. bitmap: (struct BitMap *) Pointer to the BitMap.
  788.  
  789. depth:  (long) How many BitPlanes used.
  790.  
  791. width:  (long) The width of the raster.
  792.  
  793. height: (long) The height of the raster.
  794.  
  795. Information about the size and depth of a BitMap etc is used
  796. in many places in a program and. I recommend you therefore to
  797. define some constants at the top of the program and use them
  798. rather than writing the values directly. This makes it much
  799. easier to change anything since you only need to change the
  800. code at one place, and many writing errors are avoided.
  801.  
  802. Example:
  803.  
  804. #define WIDTH  320 /* 320 pixels wide.              */
  805. #define HEIGHT 200 /* 200 lines tall.               */
  806. #define DEPTH    5 /* 5 BitPlanes gives 32 colours. */
  807.  
  808. struct BitMap my_bit_map;
  809.  
  810. InitBitMap( &my_bit_map, DEPTH, WIDTH, HEIGHT );
  811.  
  812.  
  813.  
  814. 12.2.3.4.3  ALLOCATE RASTER
  815.  
  816. Once the BitMap structure has been initialized it is time to
  817. reserve memory for each BitPlane. You reserve display memory
  818. with help of the AllocRaster() function:
  819.  
  820. Synopsis: pointer = AllocRaster( width, height );
  821.  
  822. pointer   (PLANEPTR) Pointer to the allocated memory or NULL
  823.           if enough memory could not be reserved.
  824.  
  825. width:    (long) The width of the BitMap.
  826.  
  827. height:   (long) The height of the BitMap.
  828.  
  829.  
  830. Since you may need to reserve several BitPlanes it is best to
  831. include the AllocRaster() function in a loop. Remember to check
  832. that you have got the memory you asked for! Finally, the memory
  833. you get is probably filled with a lot of trash, and it is best
  834. to clear it before you start to use it. The fastest way to
  835. clear large rectangular memory areas is to use the Blitter,
  836. and you do it by calling the function BltClear():
  837.  
  838. Synopsis: BltClear( pointer, bytes, flags );
  839.  
  840. pointer   (char *) Pointer to the memory.
  841.  
  842. bytes:    (long) The lower 16 bits tells the blitter how many
  843.           bytes per row, and the upper 16 bits how many rows.
  844.           This value is automatically calculated for you with
  845.           help of the macro RASSIZE(). Just give RASSIZE() the
  846.           correct width and height and it will return the
  847.           correct value. [RASSIZE() is defined in file
  848.           "gfx.h".]
  849.  
  850. flags:    (long) Set bit 0 to force the function to wait until
  851.           the Blitter has finished with your request.
  852.  
  853. Here is an example on how to allocate display memory, check it
  854. and clear it: (Remember that you muse deallocate ALL memory you
  855. have allocated! See below for more information.)
  856.  
  857. for( loop = 0; loop < DEPTH; loop++ )
  858. {
  859.   my_bit_map.Planes[ loop ] = AllocRaster( WIDTH, HEIGHT );
  860.  
  861.   if( my_bit_map.Planes[ loop ] == NULL )
  862.     clean_up(); /* Leave */
  863.  
  864.   BltClear( my_bit_map.Planes[ loop ], RASSIZE( WIDTH, HEIGHT ), 0 );
  865. }
  866.  
  867.  
  868.  
  869. 12.2.3.5  RASINFO
  870.  
  871. The RasInfo structure contains information like were the BitMap
  872. structure is, and the Raster's x/y offset. If you use the
  873. special display mode "Dual Playfields" it will also contain a
  874. pointer to the second Playfield.
  875.  
  876.  
  877.  
  878. 12.2.3.5.1  RASINFO STRUCTURE
  879.  
  880. The RasInfo structure look like this: [Defined in file: "view.h"]
  881.  
  882. struct RasInfo
  883. {
  884.   struct RasInfo *Next;
  885.   struct BitMap *BitMap;
  886.   SHORT RxOffset, RyOffset;
  887. };
  888.  
  889. Next:     If you use the special display mode "Dual Playfields"
  890.           this pointer will contain the address to the second
  891.           playfield. (Playfield one RasInfo's structure will
  892.           have a pointer to the second Playfield's RasInfo
  893.           structure which pointer will point to NULL.)
  894.  
  895. BitMap:   Pointer to the BitMap.
  896.  
  897. RxOffset: X offset of the Raster. (By changing the RxOffset and
  898.           RyOffset values you can scroll the whole Raster very
  899.           fast.)
  900.  
  901. RyOffset: Y offset of the Raster.
  902.  
  903.  
  904.  
  905. 12.2.3.5.2  DECLARE AND INITIALIZE A RASINFO STRUCTURE
  906.  
  907. Here is an example on how to declare and initialize a RasInfo
  908. structure:
  909.  
  910. /* Declare a RasInfo structure: */
  911. struct RasInfo my_ras_info;
  912.  
  913. /* Prepare the RasInfo structure: */
  914. my_ras_info.BitMap = &my_bit_map; /* Pointer to the BitMap   */
  915.                                   /* structure.              */
  916. my_ras_info.RxOffset = 0;         /* The top left corner of  */
  917. my_ras_info.RyOffset = 0;         /* the Raster should be at */
  918.                                   /* the top left corner of  */
  919.                                   /* the display.            */
  920. my_ras_info.Next = NULL;          /* Single playfield - only */
  921.                                   /* one RasInfo structure   */
  922.                                   /* is necessary.           */
  923.  
  924.  
  925.  
  926. 12.2.3.6  MAKEVPORT()
  927.  
  928. Once you have initialized all necessary structures you need to
  929. prepare the Amiga's hardware (especially the Copper) so they
  930. can create the display you have asked for. Each ViewPort can
  931. have its own resolution, size, colour list etc and you must
  932. therefore prepare every ViewPort by calling the MakeVPort()
  933. function.
  934.  
  935. Synopsis: MakeVPort( view, viewport ); 
  936.  
  937. view:     (struct View *) Pointer to the ViewPort's View.
  938.  
  939. viewport: (struct ViewPort *) Pointer to the ViewPort.
  940.  
  941.  
  942. NOTE! You have to prepare EVERY ViewPort you are going to use!
  943.  
  944.  
  945.  
  946. 12.2.3.7  MRGCOP()
  947.  
  948. All ViewPort's special display instructions together with other
  949. display instructions used by the Sprite hardware etc must be
  950. combined before you can show the display. All these instructions
  951. are combined with one single function call: MrgCop(). MrgCop()
  952. will merge all coprocessors' display instructions into one
  953. list.
  954.  
  955. Synopsis: MrgCop( view );
  956.  
  957. view:     (struct View *) Pointer to the View.
  958.  
  959.  
  960.  
  961. 12.2.3.8  LOADVIEW()
  962.  
  963. You can now at last show the display. You do it by calling the
  964. LoadView() function:
  965.  
  966. Synopsis: LoadView( view );
  967.  
  968. view:     (struct View *) Pointer to the View.
  969.  
  970.  
  971. You have to remember that you have now created your own display
  972. and when your program terminates you MUST return the old
  973. display! You must therefore store a pointer to the old display
  974. before you turn on your own. You can find a pointer to the
  975. current View in the GfxBase structure.
  976.  
  977. struct View *old_view;
  978.  
  979. old_view = GfxBase->ActiView;
  980.  
  981.  
  982.  
  983. 12.2.4  CLOSE A DISPLAY
  984.  
  985. When you close your display you have to remember to restore the
  986. old view by calling the LoadView() structure with a pointer to
  987. the old View structure: LoadView( old_view );
  988.  
  989. You must also return some memory that was automatically
  990. reserved when you called the MakeVPort() and MrgCop() functions.
  991. You should therefore call the FreeVPortCopLists() function for
  992. every ViewPort you have created.
  993.  
  994. Synopsis: FreeVPortCopLists( viewport );
  995.  
  996. view:     (struct ViewPort *) Pointer to the ViewPort.
  997.  
  998.  
  999. You must also call the FreeCprList() function for every View
  1000. you have created. You give the function a pointer to the cprlist
  1001. structure (LOFCprList). If you have created an interlaced View
  1002. you must also free a special cprlist structure (SHFCprList)
  1003. which is only used for interlaced Views.
  1004.  
  1005. Synopsis: FreeCprList( cprlist );
  1006.  
  1007. cprlist:  (struct cprlist *) Pointer to the View's cprlist
  1008.           (LOFCprList) structure. If the View was interlaced
  1009.           you must also call the FreeCprList function with a
  1010.           pointer to the SHFCprList.
  1011.  
  1012.  
  1013. The display memory you have allocated for the Raster must also
  1014. be deallocated. You deallocate the Raster by calling the
  1015. FreeRaster() function with a pointer to one Bitplane. You must
  1016. call this function for every Bitplane you have allocated!
  1017.  
  1018. Synopsis: FreeRaster( bitplane, width, height );
  1019.  
  1020. bitplane: (PLANEPTR) Pointer to a Bitplane.
  1021.  
  1022. width:    (long) The Bitplane's width.
  1023.  
  1024. height:   (long) The Bitplane's height.
  1025.  
  1026.  
  1027. Finally you have to deallocate the ColorMap structure that was
  1028. automatically allocated and initialized by the GetColorMap()
  1029. function. You deallocate a colour map by calling the
  1030. FreeColorMap() function.
  1031.  
  1032. Synopsis: FreeColorMap( colormap );
  1033.  
  1034. colormap: (struct ColorMap *) Pointer to the ColorMap structure.
  1035.  
  1036.  
  1037. Here is an example on how to close a display:
  1038.  
  1039. /* 1. Restore the old View: */
  1040. LoadView( old_view );
  1041.  
  1042. /* 2. Deallocate the ViewPort's display instructions: */
  1043. FreeVPortCopLists( &my_view_port );
  1044.  
  1045. /* 3. Deallocate the View's display instructions: */
  1046. FreeCprList( my_view.LOFCprList );
  1047.  
  1048. /* 4. Deallocate the display memory, BitPlane for BitPlane: */
  1049. for( loop = 0; loop < DEPTH; loop++ )
  1050.   FreeRaster( my_bit_map.Planes[ loop ], WIDTH, HEIGHT );
  1051.  
  1052. /* 5. Deallocate the ColorMap: */
  1053. FreeColorMap( my_view_port.ColorMap );
  1054.  
  1055.  
  1056. 12.2.5  EXAMPLE
  1057.  
  1058. Here is an example on how to open a high resolution NTSC
  1059. (American) display. This is what has to be done:
  1060.  
  1061.  1. Prepare the View.
  1062.  2.     - " -   ViewPort.
  1063.  3.     - " -   ColorMap.
  1064.  4.     - " -   BitMap.
  1065.  5.     - " -   RasInfo.
  1066.  6. Prepare the Amiga with MakeVPort() and MrgCop().
  1067.  8. Show the new View.
  1068.  9. The View is on and it is now up to you to do what you want.
  1069. 10. Restore the old View.
  1070. 11. Free all allocated resources and leave.
  1071.  
  1072.  
  1073. #include <intuition/intuition.h>
  1074. #include <graphics/gfxbase.h>
  1075.  
  1076.  
  1077. #define WIDTH  640 /* 640 pixels wide (high resolution)    */
  1078. #define HEIGHT 200 /* 200 lines high (non interlaced NTSC) */ 
  1079. #define DEPTH    3 /* 3 BitPlanes, gives eight colours.    */
  1080. #define COLOURS  8 /* 2^3 = 8                              */
  1081.  
  1082.  
  1083. struct IntuitionBase *IntuitionBase;
  1084. struct GfxBase *GfxBase;
  1085.  
  1086.  
  1087. struct View my_view;
  1088. struct View *my_old_view;
  1089. struct ViewPort my_view_port;
  1090. struct RasInfo my_ras_info;
  1091. struct BitMap my_bit_map;
  1092. struct RastPort my_rast_port;
  1093.  
  1094.  
  1095. UWORD my_color_table[] =
  1096. {
  1097.   0x000, /* Colour 0, Black       */
  1098.   0x800, /* Colour 1, Red         */
  1099.   0xF00, /* Colour 2, Light red   */
  1100.   0x080, /* Colour 3, Green       */
  1101.   0x0F0, /* Colour 4, Light green */
  1102.   0x008, /* Colour 5, Blue        */
  1103.   0x00F, /* Colour 6, Light Blue  */
  1104.   0xFFF, /* Colour 7, White       */
  1105. };
  1106.  
  1107.  
  1108. void clean_up();
  1109. void main();
  1110.  
  1111.  
  1112. void main()
  1113. {
  1114.   UWORD *pointer;
  1115.   int loop;
  1116.   
  1117.  
  1118.   /* Open the Intuition library: */
  1119.   IntuitionBase = (struct IntuitionBase *)
  1120.     OpenLibrary( "intuition.library", 0 );
  1121.   if( !IntuitionBase )
  1122.     clean_up( "Could NOT open the Intuition library!" );
  1123.  
  1124.   /* Open the Graphics library: */
  1125.   GfxBase = (struct GfxBase *)
  1126.     OpenLibrary( "graphics.library", 0 );
  1127.   if( !GfxBase )
  1128.     clean_up( "Could NOT open the Graphics library!" );
  1129.  
  1130.  
  1131.   /* Save the current View, so we can restore it later: */
  1132.   my_old_view = GfxBase->ActiView;
  1133.  
  1134.  
  1135.   /* 1. Prepare the View structure, and give it a pointer to */
  1136.   /*    the first ViewPort:                                  */
  1137.   InitView( &my_view );
  1138.   my_view.ViewPort = &my_view_port;
  1139.  
  1140.  
  1141.   /* 2. Prepare the ViewPort structure, and set some important values: */
  1142.   InitVPort( &my_view_port );
  1143.   my_view_port.DWidth = WIDTH;         /* Set the width.                */
  1144.   my_view_port.DHeight = HEIGHT;       /* Set the height.               */
  1145.   my_view_port.RasInfo = &my_ras_info; /* Give it a pointer to RasInfo. */
  1146.   my_view_port.Modes = HIRES;          /* High resolution.              */
  1147.  
  1148.  
  1149.   /* 3. Get a colour map, link it to the ViewPort, and prepare it: */
  1150.   my_view_port.ColorMap = (struct ColorMap *) GetColorMap( COLOURS );
  1151.   if( my_view_port.ColorMap == NULL )
  1152.     clean_up( "Could NOT get a ColorMap!" );
  1153.  
  1154.   /* Get a pointer to the colour map: */
  1155.   pointer = (UWORD *) my_view_port.ColorMap->ColorTable;
  1156.  
  1157.   /* Set the colours: */
  1158.   for( loop = 0; loop < COLOURS; loop++ )
  1159.     *pointer++ = my_color_table[ loop ];
  1160.  
  1161.  
  1162.   /* 4. Prepare the BitMap: */
  1163.   InitBitMap( &my_bit_map, DEPTH, WIDTH, HEIGHT );
  1164.  
  1165.   /* Allocate memory for the Raster: */ 
  1166.   for( loop = 0; loop < DEPTH; loop++ )
  1167.   {
  1168.     my_bit_map.Planes[ loop ] = (PLANEPTR) AllocRaster( WIDTH, HEIGHT );
  1169.     if( my_bit_map.Planes[ loop ] == NULL )
  1170.       clean_up( "Could NOT allocate enough memory for the raster!" );
  1171.  
  1172.     /* Clear the display memory with help of the Blitter: */
  1173.     BltClear( my_bit_map.Planes[ loop ], RASSIZE( WIDTH, HEIGHT ), 0 );
  1174.   }
  1175.  
  1176.   
  1177.   /* 5. Prepare the RasInfo structure: */
  1178.   my_ras_info.BitMap = &my_bit_map; /* Pointer to the BitMap structure.  */
  1179.   my_ras_info.RxOffset = 0;         /* The top left corner of the Raster */
  1180.   my_ras_info.RyOffset = 0;         /* should be at the top left corner  */
  1181.                                     /* of the display.                   */
  1182.   my_ras_info.Next = NULL;          /* Single playfield - only one       */
  1183.                                     /* RasInfo structure is necessary.   */
  1184.  
  1185.   /* 6. Create the display: */
  1186.   MakeVPort( &my_view, &my_view_port );
  1187.   MrgCop( &my_view );
  1188.  
  1189.  
  1190.   /* 7. Prepare the RastPort, and give it a pointer to the BitMap. */
  1191.   InitRastPort( &my_rast_port );
  1192.   my_rast_port.BitMap = &my_bit_map;
  1193.   
  1194.  
  1195.   /* 8. Show the new View: */
  1196.   LoadView( &my_view );
  1197.  
  1198.  
  1199.   /* 9. Your View is displayed and you can  */
  1200.   /*    now do whatever you want with it.   */
  1201.  
  1202.  
  1203.   /* 10. Restore the old View: */
  1204.   LoadView( my_old_view );
  1205.  
  1206.  
  1207.   /* 11. Free all allocated resources and leave. */
  1208.   clean_up( "THE END" );
  1209. }
  1210.  
  1211.  
  1212. /* Returns all allocated resources: */
  1213. void clean_up( message )
  1214. STRPTR message;
  1215. {
  1216.   int loop;
  1217.  
  1218.   /* Free automatically allocated display structures: */
  1219.   FreeVPortCopLists( &my_view_port );
  1220.   FreeCprList( my_view.LOFCprList );
  1221.   
  1222.   /* Deallocate the display memory, BitPlane for BitPlane: */
  1223.   for( loop = 0; loop < DEPTH; loop++ )
  1224.     if( my_bit_map.Planes[ loop ] )
  1225.       FreeRaster( my_bit_map.Planes[ loop ], WIDTH, HEIGHT );
  1226.  
  1227.   /* Deallocate the ColorMap: */
  1228.   if( my_view_port.ColorMap ) FreeColorMap( my_view_port.ColorMap );
  1229.  
  1230.   /* Close the Graphics library: */
  1231.   if( GfxBase ) CloseLibrary( GfxBase );
  1232.  
  1233.   /* Close the Intuition library: */
  1234.   if( IntuitionBase ) CloseLibrary( IntuitionBase );
  1235.  
  1236.   /* Print the message and leave: */
  1237.   printf( "%s\n", message ); 
  1238.   exit();
  1239. }
  1240.  
  1241.  
  1242.  
  1243. 12.3  DRAW
  1244.  
  1245. We have described how to create and open a display, and we will
  1246. now look at all different drawing routines the Amiga offers.
  1247. The Amiga allows you to draw single dots and lines as well as
  1248. complex figures. These routines can be combined with masks and
  1249. multicoloured patterns to great effect. The Amiga offers also
  1250. three different ways of drawing filled objects. You can even
  1251. scroll, copy and logically combine rectangular areas with
  1252. help of the fast Blitter.
  1253.  
  1254.  
  1255.  
  1256. 12.3.1  RASTPORT
  1257.  
  1258. Before you can start using the drawing routines you still need
  1259. to declare and initialize one more structure. ("Not one more!"
  1260. I can hear you say.) The reason why we need one more structure
  1261. is that most of the drawing routines need to know what pen
  1262. colour, pattern and mask (described later in this chapter) you
  1263. have chosen. This kind of information is therefore stored in a
  1264. structure called RastPort.
  1265.  
  1266.  
  1267.  
  1268. 12.3.1.1  RASTPORT STRUCTURE
  1269.  
  1270. The RastPort structure look like this: [Defined in file:
  1271. "rastport.h"] (Luckily you normally do not need to bother too
  1272. much about this structure.)
  1273.  
  1274. struct RastPort
  1275. {
  1276.   struct Layer *Layer;
  1277.   struct BitMap *BitMap;
  1278.   USHORT *AreaPtrn;
  1279.   struct TmpRas *TmpRas;
  1280.   struct AreaInfo *AreaInfo;
  1281.   struct GelsInfo *GelsInfo;
  1282.   UBYTE Mask;
  1283.   BYTE FgPen;
  1284.   BYTE BgPen;
  1285.   BYTE AOlPen;
  1286.   BYTE DrawMode;
  1287.   BYTE AreaPtSz;
  1288.   BYTE linpatcnt;
  1289.   BYTE dummy;
  1290.   USHORT Flags;
  1291.   USHORT LinePtrn;
  1292.   SHORT cp_x, cp_y;
  1293.   UBYTE minterms[8];
  1294.   SHORT PenWidth;
  1295.   SHORT PenHeight;
  1296.   struct TextFont *Font;
  1297.   UBYTE AlgoStyle;
  1298.   UBYTE TxFlags;
  1299.   UWORD TxHeight;
  1300.   UWORD TxWidth;
  1301.   UWORD TxBaseline;
  1302.   WORD TxSpacing;
  1303.   APTR *RP_User;
  1304.   ULONG longreserved[2];
  1305.   UWORD wordreserved[7];
  1306.   UBYTE reserved[8];
  1307. };
  1308.  
  1309. Layer:        Pointer to a Layer structure.
  1310.  
  1311. BitMap:       Pointer to this RastPort's BitMap structure.
  1312.  
  1313. AreaPtrn:     Pointer to an array of USHORTs that is used to
  1314.               create the area fill pattern.
  1315.  
  1316. TmpRas:       Pointer to a TmpRas structure. Used by the
  1317.               AreaMove(), AreaDraw() and AreaEnd() functions.
  1318.               (See below for more information.)
  1319.  
  1320. AreaInfo:     Pointer to an AreaInfo structure. Also used by
  1321.               the AreaMove(), AreaDraw() and AreaEnd()
  1322.               functions.
  1323.  
  1324. GelsInfo:     Pointer to a GelsInfo structure. Used by animation
  1325.               routines (VSprites and BOSs).
  1326.  
  1327. Mask:         This mask allows you determine which BitPlanes
  1328.               should be affected by the drawing routines. The
  1329.               first bit represents BitPlane zero, the second
  1330.               bit represents BitPlane one and so on. If the bit
  1331.               is on (1) that BitPlane will be affected. If the
  1332.               bit is off (0) that BitPlane will not be affected
  1333.               by the drawing routines.
  1334.  
  1335.               For example, if the mask value is set to 0xFF
  1336.               (0xFF hexadecimal = 11111111 binary) all
  1337.               BitPlanes will be affected by the drawing
  1338.               routines. If the mask value is set to 0xF6
  1339.               (0xF6 hexadecimal = 11110110 binary) BitPlane
  1340.               zero and three will not be affected.
  1341.  
  1342. FgPen:        Foreground pen's colour.
  1343.  
  1344. BgPen:        Backgrounds pen's colour.
  1345.  
  1346. AOlPen:       Areaoutline pen's colour.
  1347.  
  1348. DrawMode:     There exist four different types of drawing
  1349.               modes:
  1350.  
  1351.               JAM1       Where you write the foreground pen
  1352.                          will be used to replace the old colour,
  1353.                          and where you do not write the
  1354.                          background is unchanged. For example,
  1355.                          the FgPen is set to colour five and
  1356.                          draw mode to JAM1. If you then write
  1357.                          a pixel that pixel would be of colour
  1358.                          five, if you write a character that
  1359.                          character would be of colour five and
  1360.                          the background unchanged. (One colour
  1361.                          jammed into the Raster.) 
  1362.  
  1363.               JAM2       Where you write the foreground pen will
  1364.                          be used to replace the old colour,
  1365.                          and where you do not write the back-
  1366.                          ground pen will be used. For example,
  1367.                          the FgPen is set to colour five BgPen
  1368.                          to colour six and draw mode to JAM2.
  1369.                          If you then write a pixel that pixel
  1370.                          would be of colour five, if you write
  1371.                          a character that character would be of
  1372.                          colour five and the background colour
  1373.                          would be six. (Two colour jammed into
  1374.                          the raster.)
  1375.  
  1376.               COMPLEMENT Each pixel you draw will be drawn with
  1377.                          the binary complement colour. Where
  1378.                          you write 1's the corresponding bit in
  1379.                          the Raster will be reversed. The
  1380.                          advantage with this drawing mode is
  1381.                          that if you write twice on the same
  1382.                          spot the old picture will be restored.
  1383.  
  1384.               INVERSVID  This mode is only used for text and is
  1385.                          either combined with JAM1 or JAM2.
  1386.                          INVERSVID|JAM1 Only the background
  1387.                                         is drawn with the FgPen.
  1388.                          INVERSVID|JAM2 The background is drawn
  1389.                                         with the FgPen, and the
  1390.                                         characters with the
  1391.                                         BgPen.
  1392.  
  1393. AreaPtSz:     The height of a pattern (see below) must be a
  1394.               power of two, and that value (2^x) is stored here.
  1395.               If the AreaPtSz is set to 4, the pattern is 2^4 =
  1396.               16 lines tall. (If you use multicoloured patterns
  1397.               the AreaPtSz value should be negative. Set the
  1398.               AreaPtSz to -3 if you will use an eight lines
  1399.               tall multicoloured pattern. 2^3 = 8) 
  1400.  
  1401. linpatcnt:    Used to create line pattern.
  1402.  
  1403. dummy:        A trash are were dummy values are stored.
  1404.  
  1405. Flags:        If the AREAOUTLINE flag is set all "AreaFill
  1406.               routines" will draw a thin line around all areas
  1407.               that are filled with help of the AOlPen.
  1408.               
  1409.               If the RastPort is double-buffered the DBUFFER
  1410.               flag is set.
  1411.  
  1412. LinePtrn:     16 bits used for the line pattern. A value of
  1413.               0x9669 (hexadecimal) will create a pattern like
  1414.               this: 1001011001101001.
  1415.  
  1416. cp_x:         Current pen's X position.
  1417.  
  1418. cp_y:         Current pen's Y position.
  1419.  
  1420. minterms:     Extra memory space.
  1421.  
  1422. PenWidth:     The width of the pen (not used by the drawing
  1423.               routines).
  1424.  
  1425. PenHeight:    The height of the pen (not used by the drawing
  1426.               routines).
  1427.  
  1428. Font:         Pointer to a TextFont structure.
  1429.  
  1430. AlgoStyle:    The style that was algorithmically generated. (If
  1431.               the font does not support for example Underline,
  1432.               Bold or Italic the Amiga can generate them itself
  1433.               with help of some algorythms.
  1434.  
  1435. TxFlags:      Special text flags.
  1436.  
  1437. TxHeight:     The height of the characters.
  1438.  
  1439. TxWidth:      The nominal width of the characters.
  1440.  
  1441. TxBaseline:   The position of the text's baseline.
  1442.  
  1443. TxSpacing:    Spacing between each character.
  1444.  
  1445. RP_User:      Special variables and memory areas that is of no
  1446.               use for us. Used only by the Amiga and in future
  1447.               versions of the Graphics system.
  1448.  
  1449. longreserved:                 - " -
  1450.  
  1451. wordreserved:                 - " -
  1452.  
  1453. reserved:                     - " -
  1454.  
  1455.  
  1456. NOTE! You very rarely need to change or examine these values
  1457. directly. You normally use (and should use) functions which
  1458. are described below in order to change any values.
  1459.  
  1460.  
  1461.  
  1462. 12.3.1.2  PREPARE A RASTPORT
  1463.  
  1464. To prepare a RastPort you need to declare a RastPort structure
  1465. and initialize it by calling the InitRastPort() function with
  1466. a pointer to the RastPort as only parameter.
  1467.  
  1468. Synopsis:  InitRastPort( rast_port );
  1469.  
  1470. rast_port: (RastPort *) Pointer to the RastPort that should be
  1471.            Initialized.
  1472.  
  1473.  
  1474. The last thing you have to do is to give your RastPort a
  1475. pointer to your BitMap structure. Here is a short example:
  1476.  
  1477. /* 1. Declare a RastPort structure: */
  1478. struct RastPort my_rast_port;
  1479.  
  1480. /* 2. Initialize the RastPort with help of the */
  1481. /* InitRastPort() function:                    */
  1482. InitRastPort( &my_rast_port );
  1483.  
  1484. /* 3. Give the RastPort a pointer to your BitMap structure: */
  1485. /* [We assume that the BitMap structure have been correctly */
  1486. /* declared and initialized as described above.]            */
  1487. my_rast_port.BitMap = &my_bit_map;
  1488.  
  1489.  
  1490.  
  1491. 12.3.2  DRAWING PENS
  1492.  
  1493. The low level graphics drawing routines use three different
  1494. types of drawing pens:
  1495.  
  1496. FgPen:  The foreground pen is the most commonly used pen.
  1497.  
  1498. BgPen:  The background pen is normally used to draw the
  1499.         background with, for example if you are writing text.
  1500.  
  1501. AOlPen: The Areaoutline pen is used to outline areas that are
  1502.         filled with any of the AreaFill routines.
  1503.  
  1504. NOTE! The drawing mode will determine which pens will used.
  1505.  
  1506.  
  1507. You use the SetAPen() function to change the FgPen's colour:
  1508.  
  1509. Synopsis:   SetAPen( rast_port, new_colour );
  1510.  
  1511. rast_port:  (struct RastPort *) Pointer to the RastPort that
  1512.             should be affected.
  1513.  
  1514. new_colour: (long) A new colour value.
  1515.  
  1516.  
  1517. You use the SetBPen() function to change the BgPen's colour:
  1518.  
  1519. Synopsis:   SetBPen( rast_port, new_colour );
  1520.  
  1521. rast_port:  (struct RastPort *) Pointer to the RastPort that
  1522.             should be affected.
  1523.  
  1524. new_colour: (long) A new colour value.
  1525.  
  1526.  
  1527. You use the SetOPen() macro to change the AOlPen's colour:
  1528. Note! This is not a function. It is actually a macro that is
  1529. defined in the header file "gfxmacros.h". If you want to use
  1530. this function you have to remember to include this file.
  1531.  
  1532. Synopsis:   SetOPen( rast_port, new_colour );
  1533.  
  1534. rast_port:  (struct RastPort *) Pointer to the RastPort that
  1535.             should be affected.
  1536.  
  1537. new_colour: (long) A new colour value.
  1538.  
  1539.  
  1540.  
  1541. 12.3.3  DRAWING MODES
  1542.  
  1543. Five different drawingmodes are supported by the Amiga:
  1544.  
  1545. JAM1           The FgPen will be used, the background
  1546.                unchanged. (One colour jammed into a Raster.)
  1547.  
  1548. JAM2           The FgPen will be used as foreground pen while
  1549.                the background (when you are writing text for
  1550.                example) will be filled with the BgPen's colour.
  1551.                (Two colours are jammed into a Raster.)
  1552.  
  1553. COMPLEMENT     Each pixel affected will be drawn with the binary
  1554.                complement colour. Where you write 1's the
  1555.                corresponding bit in the Raster will be reversed.
  1556.  
  1557. INVERSVID|JAM1 This mode is only use together with text. Only
  1558.                the background of the text will be drawn with
  1559.                the FgPen.
  1560.  
  1561. INVERSVID|JAM2 This mode is only use together with text. The
  1562.                background of the text will be drawn with the
  1563.                FgPen, and the characters itself with the BgPen.
  1564.  
  1565.  
  1566. To set the drawing mode you use the SetDrMd() function:
  1567.  
  1568. Synopsis:  SetDrMd( rast_port, new_mode );
  1569.  
  1570. rast_port: (struct RastPort *) Pointer to the RastPort that
  1571.            should be affected.
  1572.  
  1573. new_mode:  (long) The new drawing mode. Set one of the
  1574.            following: JAM1, JAM2, COMPLEMENT, INVERSVID|JAM1
  1575.            or INVERSVID|JAM2.
  1576.  
  1577.  
  1578.  
  1579. 12.3.4  PATTERNS
  1580.  
  1581. Amiga's drawing routines allow you to use patterns. You may use
  1582. both line pattern as well as area patterns which may be two or
  1583. multicoloured. Line patterns are perfect when you are drawing
  1584. diagrams, borders etc. Area pattern can be used to fill any
  1585. type of object on the screen with help of the filling routines.
  1586. Many colours and different patterns give you great flexibility
  1587. to create interesting and good looking displays.
  1588.  
  1589.  
  1590.  
  1591. 12.3.4.1  LINE PATTERNS
  1592.  
  1593. Line patterns are 16 bits wide and each bit represents one dot.
  1594. The line pattern is initially set to 0xFFFF (1111111111111111)
  1595. which generates solid lines. To create a pattern of two dots
  1596. then two spaces then two dots again and so on you would set the
  1597. line pattern to 0xCCCC (1100110011001100).
  1598.  
  1599. You change the line pattern value with help of the SetDrPt()
  1600. macro. Note! This is not a function. It is actually a macro
  1601. that is defined in the header file "gfxmacros.h". If you want
  1602. to use this function you have to remember to include this file.
  1603.  
  1604. Synopsis:     SetDrPt( rast_port, line_pattern );
  1605.  
  1606. rast_port:    (struct RastPort *) Pointer to the RastPort that
  1607.               should be affected.
  1608.  
  1609. line_pattern: (UWORD) The pattern. Each bit represents one dot.
  1610.               To generate solid lines you set the pattern value
  1611.               to 0xFFFF [hex] (1111111111111111 [bin]).
  1612.  
  1613.  
  1614. Here are some commonly used pattern and the corresponding
  1615. pattern values:
  1616.  
  1617.   Description       Pattern [bin]     Pattern value [hex]
  1618.   -------------------------------------------------------
  1619.   solid line        1111111111111111  0xFFFF
  1620.   large dotty line  1111000011110000  0xF0F0
  1621.   medium dotty line 1100110011001100  0xCCCC
  1622.   small dotty line  1000100010001000  0x8888
  1623.   grey line         1010101010101010  0xAAAA
  1624.  
  1625.  
  1626.  
  1627. 12.3.4.2  AREA PATTERNS
  1628.  
  1629. Area patterns are 16 bits wide and a power of two (1, 2, 4, 8,
  1630. 16, 32, ... ) lines tall. To generate an area pattern you must
  1631. therefore declare and initialize an array of UWORDS. Each bit
  1632. in the array represents one dot. To create a pattern with a lot
  1633. of small squares you would declare and initialize the array
  1634. something like this:
  1635.  
  1636. UWORD area_pattern =
  1637. {
  1638.   0xF0F0, /* 1111000011110000 */
  1639.   0xF0F0, /* 1111000011110000 */
  1640.   0xF0F0, /* 1111000011110000 */
  1641.   0xF0F0, /* 1111000011110000 */
  1642.   0x0F0F, /* 0000111100001111 */
  1643.   0x0F0F, /* 0000111100001111 */
  1644.   0x0F0F, /* 0000111100001111 */
  1645.   0x0F0F, /* 0000111100001111 */
  1646. };
  1647.  
  1648. To set the pattern you call the SetAfPt() macro with a pointer
  1649. to your RastPort as well as you new pattern as parameters.
  1650. Note! This is not a function. It is actually a macro that is
  1651. defined in the header file "gfxmacros.h". If you want to use
  1652. this function you have to remember to include this file.
  1653.  
  1654. Synopsis:     SetAfPt( rast_port, area_pattern, pow2 );
  1655.  
  1656. rast_port:    (struct RastPort *) Pointer to the RastPort that
  1657.               should be affected.
  1658.  
  1659. area_pattern: (UWORD) Pointer to an array of UWORDS that
  1660.               generate the pattern. Each bit in the array
  1661.               represents one dot.
  1662.  
  1663. pow2:         (BYTE) The pattern must be two to the power of
  1664.               pow2 lines tall. If the pattern is one line tall
  1665.               pow2 should be set to 0, if the pattern is two
  1666.               lines tall pow2 should be set to 1, if the
  1667.               pattern is four lines tall pow2 should be set to
  1668.               2, and so on. (If you use multicoloured patterns
  1669.               the pow2 should be negative. A sixteen lines
  1670.               tall multicoloured pattern should therefore have
  1671.               the pow2 value set to -4 [2^4 = 16].)
  1672.  
  1673.  
  1674.  
  1675. 12.3.4.3  MULTICOLOURED PATTERNS
  1676.  
  1677. You may even produce multicoloured patterns. You then need to
  1678. declare an array with a depth of two or more. The larger depth
  1679. the array have the more colours can be used. Each level
  1680. represents one BitPlane.
  1681.  
  1682. Here is an area pattern array that generates eight different
  1683. coloured boxes. To get eight colours you need an array with a
  1684. depth of three. The pattern will look like this: (The numbers
  1685. are the colour registers that will be used.)
  1686.  
  1687.   0123
  1688.   0123
  1689.   4567
  1690.   4567
  1691.  
  1692. UWORD area_pattern =
  1693. {
  1694.   {         /* Plane 0          */
  1695.     0x0F0F, /* 0000111100001111 */
  1696.     0x0F0F, /* 0000111100001111 */
  1697.     0x0F0F, /* 0000111100001111 */
  1698.     0x0F0F  /* 0000111100001111 */
  1699.   },
  1700.   {         /* Plane 1          */
  1701.     0x00FF, /* 0000000011111111 */
  1702.     0x00FF, /* 0000000011111111 */
  1703.     0x00FF, /* 0000000011111111 */
  1704.     0x00FF  /* 0000000011111111 */
  1705.   },
  1706.   {         /* Plane 2          */
  1707.     0x0000, /* 0000000000000000 */
  1708.     0x0000, /* 0000000000000000 */
  1709.     0xFFFF, /* 1111111111111111 */
  1710.     0xFFFF  /* 1111111111111111 */
  1711.   }
  1712. }; 
  1713.  
  1714.  
  1715. When you use multicoloured patterns the pow2 value in the
  1716. SetAfPt() macro should be negative. Simply put a minus in front
  1717. of the value and the drawing routines will understand that you
  1718. use multicoloured patterns.
  1719.  
  1720. When using multicoloured patterns the drawing mode should be
  1721. set to JAM2, FgPen to colour 255 and BgPen to colour 0:
  1722.  
  1723. /* Prepare to draw with multicoloured pattern: */
  1724. SetDrMd( &my_rast_port, JAM2 );
  1725. SetAPen( &my_rast_port, 255 );
  1726. SetBPen( &my_rast_port,   0 );
  1727.  
  1728. /* Set pattern: (4 lines tall -> pow2 = 2 [2^2], multicol. -2)
  1729. SetAfPt( &my_rast_port, area_pattern, -2 );
  1730.  
  1731.  
  1732.  
  1733. 12.3.5  BITPLANE MASK
  1734.  
  1735. To create special effects you can turn off BitPlanes in your
  1736. Raster so they will not be affected by the drawing routines.
  1737. The first bit in the mask represents the first BitPlane, the
  1738. second bit the second BitPlane and so on. A 1 means that the
  1739. BitPlane may be affected, while a 0 means that the BitPlane
  1740. will not be affected. To turn off BitPlane zero and two the
  1741. mask value should be set to 0xFA [hex] = 11111010 [bin].
  1742.  
  1743. The mask variable "Mask" can be found in the RastPort
  1744. structure: my_rast_port.Mask = 0xFF (All BitPlanes may be
  1745. altered.)
  1746.  
  1747.  
  1748.  
  1749. 12.3.6  DRAW SINGLE PIXELS
  1750.  
  1751. You draw single pixels with help of the WritePixel() function.
  1752.  
  1753. Synopsis:  WritePixel( rast_port, x, y );
  1754.  
  1755. rast_port: (struct RastPort *) Pointer to the RastPort that
  1756.            should be affected.
  1757.  
  1758. x:         (long) X position of the pixel. 
  1759.  
  1760. y:         (long) Y position of the pixel.
  1761.  
  1762.  
  1763.  
  1764. 12.3.7  READ SINGLE PIXELS
  1765.  
  1766. You use the ReadPixel() function in order to determine what
  1767. colour a specific pixel has. Just give it a pointer to your
  1768. RastPort and the coordinates of the pixel and the function will
  1769. return what colour value that pixel was made of.
  1770.  
  1771. Synopsis:  colour = ReadPixel( rast_port, x, y );
  1772.  
  1773. colour:    (long) ReadPixel returns the colour value of the
  1774.            specified pixel (colour 0 - 255 ) or -1 if the
  1775.            coordinates were outside the Raster.
  1776.  
  1777. rast_port: (struct RastPort *) Pointer to the RastPort which
  1778.            contain the pixel you want to examine.
  1779.  
  1780. x:         (long) X position of the pixel. 
  1781.  
  1782. y:         (long) Y position of the pixel.
  1783.  
  1784.  
  1785.  
  1786. 12.3.8  POSITION THE CURSOR
  1787.  
  1788. Before you can start drawing lines or writing text you need to
  1789. position the cursor (the position from where the line/text will
  1790. be drawn from). The cursor is nothing the user can see, it is
  1791. just the current coordinates for the drawing pen. The cursor
  1792. position can be found in the RastPort's cp_x and cp_y variables.
  1793.  
  1794. The cursor position is altered by calling the Move() function.
  1795.  
  1796. Synopsis:  Move( rast_port, x, y );
  1797.  
  1798. rast_port: (struct RastPort *) Pointer to the RastPort that
  1799.            should be affected.
  1800.  
  1801. x:         (long) The new X position. 
  1802.  
  1803. y:         (long) The new Y position.
  1804.  
  1805.  
  1806.  
  1807. 12.3.9  TEXT
  1808.  
  1809. In this chapter we will not go into deep details on how to
  1810. write characters/text. All information about changing style
  1811. and fonts will be described in a special TEXT chapter. However,
  1812. I will at least describe how to print normal plain characters
  1813. on the screen.
  1814.  
  1815. To print text you use the Text() function. It needs a pointer
  1816. to the RastPort that should be affected, a pointer to a text
  1817. string and finally a value that tells Text() how many
  1818. characters of the string should be printed. Only one line each
  1819. call may be printed, no formatting, word-wrapping etc is done.
  1820.  
  1821. Synopsis:  Text( rast_port, string, nr_of_chr );
  1822.  
  1823. rast_port: (struct RastPort *) Pointer to the RastPort that
  1824.            should be affected.
  1825.  
  1826. string:    (char *) Pointer to a text string that will be
  1827.            printed.
  1828.  
  1829. nr_of_chr: (long) The number of characters that should be
  1830.            printed.
  1831.  
  1832.  
  1833. This example prints "Hello" on the display:
  1834.   Text( &my_rast_port, "HELLO", 5 );
  1835.  
  1836.  
  1837.  
  1838. 12.3.10  DRAW SINGLE LINES
  1839.  
  1840. You draw single lines with help of the Draw() function. It will
  1841. draw a line from the current position to a new position
  1842. anywhere on the Raster.
  1843.  
  1844. Synopsis:  Draw( rast_port, x, y );
  1845.  
  1846. rast_port: (struct RastPort *) Pointer to the RastPort that
  1847.            should be affected.
  1848.  
  1849. x:         (long) The new X position. 
  1850.  
  1851. y:         (long) The new Y position.
  1852.  
  1853.  
  1854. Here is an example that will draw a triangle on the screen:
  1855.  
  1856. Move( &my_rast_port, 100, 100 ); /* Move to start position. */
  1857. Draw( &my_rast_port, 300, 100 ); /* Draw the three lines.   */
  1858. Draw( &my_rast_port, 200, 200 );
  1859. Draw( &my_rast_port, 100, 100 );
  1860.  
  1861.  
  1862.  
  1863. 12.3.11  DRAW MULTIPLE LINES
  1864.  
  1865. To draw multiple lines we use the PolyDraw() function. It needs
  1866. a pointer to an array of coordinates, a value that tells
  1867. PolyDraw() how many pairs of coordinates (x,y) will be used
  1868. and of course a pointer to the RastPort that should be
  1869. affected. A line is drawn from the current position to the
  1870. first coordinate. There a second line is drawn to the second
  1871. coordinate and so on.
  1872.  
  1873. Synopsis:    PolyDraw( rast_port, number, coordinates );
  1874.  
  1875. rast_port:   (struct RastPort *) Pointer to the RastPort that
  1876.              should be affected.
  1877.  
  1878. number:      (long) The number of coordinates (x,y) defined in
  1879.              the array.
  1880.  
  1881. coordinates: (short *) Pointer to an array of coordinates.
  1882.  
  1883.  
  1884. Here is an example that also will draw a triangle on the
  1885. screen:
  1886.  
  1887. /* Three coordinates: */
  1888. WORD coordinates[] =
  1889. {
  1890.   300, 100,
  1891.   200, 200,
  1892.   100, 100
  1893. };
  1894.  
  1895. /* Move to the start position: */
  1896. Move( &my_rast_port, 100, 100 );
  1897.  
  1898. /* Draw some lines: */
  1899. PolyDraw( &my_rast_port, 3, coordinates );
  1900.  
  1901.  
  1902.  
  1903. 12.3.12  DRAW FILLED RECTANGLES
  1904.  
  1905. To draw filled rectangles you use the RectFill function. (Note
  1906. that the area pattern will have effect here.)
  1907.  
  1908. Synopsis:  RectFill( rast_port, minx, miny, maxx, maxy );
  1909.  
  1910. rast_port: (struct RastPort *) Pointer to the RastPort that
  1911.            should be affected.
  1912.  
  1913. minx:      (long) Left position of the rectangle.
  1914.  
  1915. miny:      (long) Top          - " -
  1916.  
  1917. maxx:      (long) Right        - " -
  1918.  
  1919. maxy:      (long) Bottom       - " -
  1920.  
  1921.  
  1922.  
  1923. 12.3.13  FLOOD FILL
  1924.  
  1925. Flood fill is used when a complicated object should be filled.
  1926. There exist two different types of flood fill, Outline mode and
  1927. Colour mode. In outline mode everything will be filled with the
  1928. new colour, and the flood is only stopped when it has reached
  1929. an edge of the same colour as AOlPen. In colour mode all pixels
  1930. with the same colour and are side by side with each other will
  1931. be affected. The fill will stop first when the flood has
  1932. reached a different colour.
  1933.  
  1934. You flood fill objects with help of the Flood() function.
  1935.  
  1936. Synopsis: Flood( rast_port, mode, x, y ); 
  1937.  
  1938. rast_port: (struct RastPort *) Pointer to the RastPort that
  1939.            should be affected.
  1940.  
  1941. mode:      (long) Which mode should be used. If you want to use
  1942.            the Colour mode set the mode variable to 1, to get
  1943.            the Outline mode set the mode variable to 0.
  1944.  
  1945. x:         (long) X position where the flood fill should start.
  1946.  
  1947. y:         (long) Y position where the flood fill should start.
  1948.  
  1949.  
  1950. Here is an example that will draw a triangle and then fill it.
  1951. We set the AOlPen to the same colour as the FgPen so the flood
  1952. fill will stop when it reaches the edges, outline mode.
  1953.  
  1954. /* Set the AOlPen to the same colour as FgPen: */
  1955. SetOPen( &my_rast_port, my_rast_port.FgPen );
  1956.  
  1957. /* Draw a triangle: */
  1958. Move( &my_rast_port, 100, 100 );
  1959. Draw( &my_rast_port, 300, 100 );
  1960. Draw( &my_rast_port, 200, 200 );
  1961. Draw( &my_rast_port, 100, 100 );
  1962.  
  1963. /* Fill it: (Use the Outline mode) */
  1964. Flood( &my_rast_port, 0, 200, 150 );
  1965.  
  1966.  
  1967.  
  1968. 12.3.14  DRAW FILLED AREAS
  1969.  
  1970. The Amiga allows you to draw areas that are directly filled.
  1971. You move to a location and then starts to draw your objects.
  1972. The user will however not notice anything since no lines are
  1973. drawn. The lines are instead stored in a large vector list,
  1974. and will first be drawn and filled when you finish (close) the
  1975. object.
  1976.  
  1977.  
  1978.  
  1979. 12.3.14.1  AREAINFO AND TMPRAS STRUCTURES
  1980.  
  1981. To manage this you need to do some things:
  1982.  
  1983. 1. A buffer in which a list of all your vertices can be stored
  1984.    in. Five bytes per vertex is needed, and to create a buffer
  1985.    for 100 lines you need 500 bytes. However, the buffer must
  1986.    be word aligned, and you should therefore declare the buffer
  1987.    as a collection of words instead of bytes. Since there goes
  1988.    two bytes on every word, 500 bytes means 250 words.
  1989.    Example: UWORD my_buffer[ 250 ];
  1990.  
  1991. 2. Declare an AreaInfo structure. (Declared in file
  1992.    "rastport.h".)
  1993.    Example: struct AreaInfo my_area_info;
  1994.  
  1995. 3. Combine the buffer and the AreaInfo structure with help of
  1996.    the InitArea() function. It needs a pointer to an AreaInfo
  1997.    structure, a pointer to a memory buffer and a value that
  1998.    tells it how many vertices may be stored in the buffer.
  1999.    Example: InitArea( &my_area_info, my_buffer, 100);
  2000.  
  2001. 4. Declare a TmpRas structure. (Also declared in the file
  2002.    "rastport.h".)
  2003.    Example: struct TmpRas my_tmp_ras;
  2004.  
  2005. 5. Reserve a BitPlane large enough to store all your objects
  2006.    in. Normally you make the BitPlane equal large as the
  2007.    display. Example:
  2008.    PLANEPTR my_bit_plane;
  2009.    my_bit_plane = AllocRaster( 320, 200 );
  2010.    if( my_bit_plane == NULL )
  2011.      exit();
  2012.  
  2013. 6. Initialize and combine the TmpRas structure and the extra
  2014.    memory by calling the InitTmpRas() function. It needs a
  2015.    pointer to the TmpRas structure, a pointer to some extra
  2016.    display memory, and finally a value telling it how large
  2017.    the extra memory area is, calculated with help of the
  2018.    RASSIZE() macro. Example:
  2019.    InitTmpRas( &my_tmp_ras, my_bit_plane, RASSIZE( 320, 200 ) );
  2020.  
  2021. 7. Tell the RastPort were it can find the AreaInfo and TmpRas
  2022.    structures. Example:
  2023.    my_rast_port.AreaInfo = &my_area_info;
  2024.    my_rast_port.TmpRas = &my_tmp_ras;
  2025.  
  2026. 8. Before your program terminates it must deallocate the
  2027.    display memory it has allocated. Use the function
  2028.    FreeRaster(). Example:
  2029.    FreeRaster( my_bit_plane, 320, 200 );
  2030.  
  2031.  
  2032.  
  2033. 12.3.14.2  AREAMOVE(), AREADRAW() AND AREAEND()
  2034.  
  2035. Once the TmpRas and AreaInfo structures have been initialized,
  2036. and the RastPort know where to find them, you may start to use
  2037. the AreaFill functions. The first thing you probably would do
  2038. is to move to a new position were you want to start drawing.
  2039. You do it by calling the AreaMove() function.
  2040.  
  2041. Synopsis:  AreaMove( rast_port, x, y );
  2042.  
  2043. rast_port: (struct RastPort *) Pointer to the RastPort that
  2044.            should be affected.
  2045.  
  2046. x:         (long) Start X position.
  2047.  
  2048. y:         (long) Start Y position.
  2049.  
  2050.  
  2051. You can now start to draw with help of the AreaDraw() function.
  2052. NOTE! The user will not see anything, it is first when you
  2053. close this polygon it will be drawn and filled.
  2054.  
  2055. Synopsis:  AreaDraw( rast_port, x, y );
  2056.  
  2057. rast_port: (struct RastPort *) Pointer to the RastPort that
  2058.            should be affected.
  2059.  
  2060. x:         (long) New X position.
  2061.  
  2062. y:         (long) New Y position.
  2063.  
  2064.  
  2065. Be careful not to draw outside the Raster, it may crash the
  2066. system!
  2067.  
  2068. Once you are ready with your object you call the function
  2069. AreaEnd() and the polygon is closed and filled. You do not
  2070. need to close the polygon itself, the last line will if
  2071. necessary been drawn automatically. (If you call AreaMove()
  2072. before you have closed a polygon, it will be closed
  2073. automatically before the new polygon starts.)
  2074.  
  2075. Synopsis:  AreaEnd( rast_port );
  2076.  
  2077. rast_port: (struct RastPort *) Pointer to the RastPort that
  2078.            should be affected.
  2079.  
  2080.  
  2081.  
  2082. 12.3.14.3  TURN OFF THE OUTLINE FUNCTION
  2083.  
  2084. The areas that are filled with help of the AreaFill functions
  2085. will be outlined with the AOlPen. You can however turn this
  2086. outline function off if you do not want it. You simply call
  2087. the macro (declared in file "gfxmacros.h") BNDROFF() with a
  2088. pointer to your RastPort as only parameter.
  2089.  
  2090. Synopsis:  BNDROFF( rast_port );
  2091.  
  2092. rast_port: Pointer to the RastPort which outlinefunction should
  2093.            be turned off.
  2094.  
  2095.  
  2096.  
  2097. 12.3.14.4  EXAMPLE
  2098.  
  2099. Here is an example:
  2100.  
  2101.  
  2102. #define WIDTH  320
  2103. #define HEIGHT 200
  2104.  
  2105. /* Declare an AreaInfo and TmpRas structure: */
  2106. struct AreaInfo my_area_info;
  2107. struct TmpRas my_tmp_ras;
  2108.  
  2109. /* Vertex buffer: (100 lines, 5 bytes each gives 500 bytes */
  2110. /* which is 250 words. Must be word-aligned.)               */
  2111. UWORD my_buffer[ 250 ];
  2112.  
  2113. /* Pointer to some display memory that will be allocated: */
  2114. PLANEPTR my_bit_plane;
  2115.  
  2116. /* Initialize the AreaInfo structure. */
  2117. /* Prepare for 100 vertices:          */
  2118. InitArea( &my_area_info, my_buffer, 100);
  2119.  
  2120. /* Allocate some display memory: */
  2121. my_bit_plane = AllocRaster( WIDTH, HEIGHT );
  2122.  
  2123. /* Have we allocated it successfully? */
  2124. if( my_bit_plane == NULL )
  2125.   exit();
  2126.  
  2127. /* Prepare the TmpRas structure: */
  2128. InitTmpRas( &my_tmp_ras, my_bit_plane, RASSIZE( WIDTH, HEIGHT ) );
  2129.  
  2130. /* Tell RastPort were it can find the structures: */
  2131. my_rast_port.AreaInfo = &my_area_info;
  2132. my_rast_port.TmpRas = &my_tmp_ras;
  2133.  
  2134.  
  2135. /* Draw a filled square: */
  2136. AreaMove( my_rast_port,   0,   0 );
  2137. AreaDraw( my_rast_port, 100,   0 );
  2138. AreaDraw( my_rast_port, 100, 100 );
  2139. AreaDraw( my_rast_port,   0, 100 );
  2140. AreaEnd( my_rast_port );
  2141.  
  2142.  
  2143. /* Deallocate the extra memory: */
  2144. FreeRaster( my_bit_plane, WIDTH, HEIGHT );
  2145.  
  2146.  
  2147.  
  2148. 12.3.15  SET THE RASTER TO A SPECIFIC COLOUR
  2149.  
  2150. You set a whole Raster to a specific colour with help of the
  2151. SetRast() function.
  2152.  
  2153. Synopsis:  SetRast( rast_port, colour );
  2154.  
  2155. rast_port: (struct RastPort *) Pointer to the RastPort that
  2156.            should be affected.
  2157.  
  2158. colour:    (long) The colour reg. you want to fill the whole
  2159.            raster with.
  2160.  
  2161.  
  2162.  
  2163. 12.3.16  BLITTER
  2164.  
  2165. The Blitter is a chip inside the Amiga which is specialized in
  2166. moving and logically combining large rectangular memory areas.
  2167. It moves and works with enormous amount of data and can
  2168. therefore do a lot of hard work which would take much more time
  2169. for the main processor to do. The main processor can instead
  2170. concentrate itself on more important tasks.
  2171.  
  2172. The Blitter, also called Fat Agnus (the chip is very fat), is
  2173. the hero behind the Amigas fashinating graphics capabilities. 
  2174. It can be used to clear, scroll and copy large memory areas.
  2175. Unlike other blitters it can also logically combine memory
  2176. areas (explained later) and can therefore do a lot more
  2177. interesting things than just moving data.
  2178.  
  2179.  
  2180.  
  2181. 12.3.16.1  CLEAR RECTANGULAR MEMORY AREAS
  2182.  
  2183. You can clear memory with help of the BltClear() function. The
  2184. advantage of using this function is that it works together with
  2185. the blitter which is the fastest chip to clear memory.
  2186.  
  2187. Synopsis: BltClear( memory, count, flags );
  2188.  
  2189. memory:   (char *) Pointer to the memory that should be
  2190.           cleared.
  2191.  
  2192. count:    (long) Number of bytes that should be cleared. If you
  2193.           clear display memory you can use the macro RASSIZE()
  2194.           to calculate how many bytes the display use.
  2195.  
  2196. flags:    (long) Write 0 to allow the computer to continue
  2197.           while the blitter is still working, or write 1 which
  2198.           will force the program to wait for the blitter.
  2199.  
  2200.  
  2201.  
  2202. 12.3.16.2  SCROLL A RECTANGULAR AREA
  2203.  
  2204. You can scroll an area of a raster with help of the
  2205. ScrollRaster() function. It works together with the blitter
  2206. and is therefore very fast. The area can be moved both
  2207. vertically as well as horizontally. The area which is moved
  2208. out of the raster is lost, and the new area is filled with the
  2209. BgPen.
  2210.  
  2211. Synopsis:  ScrollRaster( rp, dx, dy, minx, miny, maxx, maxy );
  2212.  
  2213. rp:        (struct RastPort *) Pointer to the RastPort that
  2214.            should be affected.
  2215.  
  2216.  
  2217. dx:        (long) Delta X movement. (A positive number moves
  2218.            the area to the right, a negative number to the
  2219.            left.)
  2220.  
  2221. dy:        (long) Delta Y movement. (A positive number moves
  2222.            the area down, a negative number up.)
  2223.  
  2224. minx:      (long) Left edge of the rectangle.
  2225.  
  2226. miny:      (long) Top edge of the rectangle.
  2227.  
  2228. maxx:      (long) Right edge of the rectangle.
  2229.  
  2230. maxy:      (long) Bottom edge of the rectangle.
  2231.  
  2232.  
  2233.  
  2234. 12.3.16.3  COPY RECTANGULAR AREAS
  2235.  
  2236. When you are going to copy rectangular memory areas you can
  2237. either use BltBitMap() or ClipBlit(). BltBitMap() should be
  2238. used when you simply want to copy data and do not bother about
  2239. overlapping layers (windows) etc. The ClipBlit() on the other
  2240. hand should be used when you want to look out for overlapping
  2241. layers etc.
  2242.  
  2243. BltBitMap() copies BitMaps directly without worrying about
  2244. overlapping layers.
  2245.  
  2246. Synopsis: BltBitMap( sbm, sx, sy, dbm, dx, dy, w, h, flag, m, t );
  2247.  
  2248. sbm:      (struct BitMap *) Pointer to the "source" BitMap.
  2249.  
  2250. sx:       (long) X offset, source.
  2251.  
  2252. sy:       (long) Y offset, source.
  2253.  
  2254. dbm:      (struct BitMap *) Pointer to the "destination"
  2255.           BitMap.
  2256.  
  2257. dx:       (long) X offset, destination.
  2258.  
  2259. dy:       (long) Y offset, destination.
  2260.  
  2261. w:        (long) The width of the memory area that should be
  2262.           copied.
  2263.  
  2264. h:        (long) The height of the memory area that should be
  2265.           copied.
  2266.  
  2267. flag:     (long) This value tells the blitter what kind of
  2268.           logically operations should be done. See below for
  2269.           more information.
  2270.  
  2271. m:        (long) You can here define a BitMap mask, and tell
  2272.           the blitter which BitPlanes should be used, and which
  2273.           should not. The first bit represents the first
  2274.           BitPlane, the second bit the second BitPlane and so
  2275.           on. If the bit is on (1) the corresponding BitPlane
  2276.           will be used, else (0) the BitPlane will not be used.
  2277.           To turn off BitPlane zero and two, set the mask value
  2278.           to 0xFA (11111010). To use all BitPlanes set the mask
  2279.           value to 0xFF (11111111).
  2280.  
  2281. t:        (char *) If the copy overlaps and this pointer points
  2282.           to some chip-memory, the memory will be used to store
  2283.           the temporary area in. However, normally you do not
  2284.           need to bother about this value.
  2285.  
  2286.  
  2287. ClipBlit() copies BitMaps with help of Rastports and will
  2288. therefore care about overlapping layers, and should be used
  2289. if you have windows on your display.
  2290.  
  2291. Synopsis: ClipBlit( srp, sx, sy, drp, dx, dy, w, h, flag );
  2292.  
  2293. srp:      (struct RastPort *) Pointer to the "source" RastPort.
  2294.  
  2295. sx:       (long) X offset, source.
  2296.  
  2297. sy:       (long) Y offset, source.
  2298.  
  2299. drp:      (struct RastPort *) Pointer to the "destination"
  2300.           RastPort.
  2301.  
  2302. dx:       (long) X offset, destination.
  2303.  
  2304. dy:       (long) Y offset, destination.
  2305.  
  2306. w:        (long) The width of the memory area that should be
  2307.           copied.
  2308.  
  2309. h:        (long) The height of the memory area that should be
  2310.           copied.
  2311.  
  2312. flag:     (long) This value tells the blitter what kind of
  2313.           logically operations should be done. See below for
  2314.           more information.
  2315.  
  2316.  
  2317. As said above the blitter can logically combine data from the
  2318. source and destination areas. The first four bits to the left
  2319. in the flag field determines what calculations should be done.
  2320.  
  2321. If the leftmost bit is set (value 0x80) the result will be a
  2322. combination of the source and destination. If the second
  2323. leftmost bit is set (value 0x40) the result will be a
  2324. combination of the source and inverted destination. If the
  2325. third leftmost bit is set (value 0x20) the result will be a
  2326. combination of the inverted source and destination. If the
  2327. fourth leftmost bit is set (value 0x10) the result will be the
  2328. source together with destination and all inverted. See table
  2329. below:
  2330.  
  2331.   Bit       Value  Log
  2332.   --------------------
  2333.   1000 0000  0x80  SD
  2334.                     _
  2335.   0100 0000  0x40  SD
  2336.                    _
  2337.   0010 0000  0x20  SD
  2338.                    __
  2339.   0001 0000  0x10  SD
  2340.  
  2341.  
  2342. To make a normal copy the result should be only S. We can get
  2343. it by setting the flag value to 0xC0 [hex] (11000000 [bin]).
  2344. The mathematically formula will then be:
  2345.         _         _
  2346.   SD + SD = S(D + D) = S
  2347.                                         _
  2348. If you want to get the source inverted (S), set the flag value
  2349. to 0x30 [hex] (00110000 [bin]). The mathematically formula will
  2350. then be:
  2351.   _    __   _     _    _
  2352.   SD + SD = S(D + D) = S
  2353.                                  _
  2354. To get the destination inverted (D), set the flag value to 0x50
  2355. [hex] (01010000 [bin]). The mathematically formula will then
  2356. be:
  2357.    _   __   _     _    _
  2358.   SD + SD = D(S + S) = D
  2359.  
  2360.  
  2361. Here is an example that will copy a rectangular area from a
  2362. RastPort called source_rp to another RastPort called
  2363. destination_rp. The rectangular area is WIDTH pixels wide and
  2364. HEIGHT lines tall.
  2365.  
  2366. ClipBlit( &source_rp,      /* Source RastPort.              */
  2367.           0, 0,            /* Top left corner, source.      */
  2368.           &destination_rp, /* Destination RastPort.         */
  2369.           0, 0,            /* Top left corner, destination. */
  2370.           WIDTH, HEIGHT,   /* Size of the memory area.      */
  2371.           0xC0 );          /* Normal copy.                  */
  2372.  
  2373.  
  2374.  
  2375. 12.4  FUNCTIONS
  2376.  
  2377. InitView()
  2378.  
  2379.   This function will initialize a View structure.
  2380.  
  2381.   Synopsis: InitView( view );
  2382.   
  2383.   view:     (struct View *) Pointer to the View that should be
  2384.             initialized.
  2385.  
  2386.  
  2387. InitVPort()
  2388.  
  2389.   This function will initialize a ViewPort structure.
  2390.  
  2391.   Synopsis:  InitVPort( view_port );
  2392.   
  2393.   view_port: (struct ViewPort *) Pointer to the ViewPort that
  2394.              should be initialized.
  2395.  
  2396.  
  2397. GetColorMap()
  2398.  
  2399.   This function allocates and initializes a ColorMap structure.
  2400.  
  2401.   Synopsis: colormap = GetColorMap( colours );
  2402.  
  2403.   colormap: (struct ColorMap *) GetColorMap returns a pointer
  2404.             to the ColorMap structure it has allocated and
  2405.             initialized, or NULL if not enough memory.
  2406.  
  2407.   colours:  (long) A value specifying how many colours you
  2408.             want that the ColorMap structure should store.
  2409.             (1, 2, 4, 8, 16, 32)
  2410.  
  2411.  
  2412. FreeColorMap()
  2413.  
  2414.   This function deallocates the memory that was allocated by
  2415.   the GetColorMap() function. Remember to deallocate all memory
  2416.   that you allocate. For every GetColorMap() function there
  2417.   should be one FreeColorMap() function.
  2418.  
  2419.   FreeColorMap( colormap );
  2420.  
  2421.   colormap: (struct ColorMap *) Pointer to a ColorMap structure
  2422.             that GetColorMap() returned and you now want to
  2423.             deallocate.
  2424.  
  2425.  
  2426. InitBitMap()
  2427.  
  2428.   This function initializes a BitMap structure.
  2429.  
  2430.   Synopsis: InitBitMap( bitmap, depth, width, height );
  2431.  
  2432.   bitmap: (struct BitMap *) Pointer to the BitMap.
  2433.  
  2434.   depth:  (long) How many BitPlanes used.
  2435.  
  2436.   width:  (long) The width of the raster.
  2437.  
  2438.   height: (long) The height of the raster.
  2439.  
  2440.  
  2441. AllocRaster()
  2442.  
  2443.   This function reserves display memory (one BitPlane).
  2444.  
  2445.   Synopsis: pointer = AllocRaster( width, height );
  2446.  
  2447.   pointer   (PLANEPTR) Pointer to the allocated memory or NULL
  2448.             if enough memory could not be reserved.
  2449.  
  2450.   width:    (long) The width of the BitMap.
  2451.  
  2452.   height:   (long) The height of the BitMap.
  2453.  
  2454.  
  2455. BltClear()
  2456.  
  2457.   This function clears large rectangular memory areas. This
  2458.   function work together with the blitter and is therefore very
  2459.   fast.
  2460.  
  2461.   Synopsis: BltClear( pointer, bytes, flags );
  2462.  
  2463.   pointer   (char *) Pointer to the memory.
  2464.  
  2465.   bytes:    (long) The lower 16 bits tells the blitter how many
  2466.             bytes per row, and the upper 16 bits how many rows.
  2467.             This value is automatically calculated for you with
  2468.             help of the macro RASSIZE(). Just give RASSIZE()
  2469.             the correct width and height and it will return the
  2470.             correct value. [RASSIZE() is defined in file
  2471.             "gfx.h".]
  2472.  
  2473.   flags:    (long) Set bit 0 to force the function to wait
  2474.             until the Blitter has finished with your request.
  2475.  
  2476.  
  2477. MakeVPort()
  2478.  
  2479.   This function prepares the Amiga's hardware (especially the
  2480.   Copper) to display a ViewPort. NOTE! You have to prepare
  2481.   EVERY ViewPort you are going to use!
  2482.  
  2483.   Synopsis: MakeVPort( view, viewport ); 
  2484.  
  2485.   view:     (struct View *) Pointer to the ViewPort's View.
  2486.  
  2487.   viewport: (struct ViewPort *) Pointer to the ViewPort.
  2488.  
  2489.  
  2490. MrgCop()
  2491.  
  2492.   This function puts together all displayinstructions and
  2493.   prepares the view to be showed.
  2494.  
  2495.   Synopsis: MrgCop( view );
  2496.  
  2497.   view:     (struct View *) Pointer to the View.
  2498.  
  2499.  
  2500. LoadView()
  2501.  
  2502.   This function will start showing a View. Remember that when
  2503.   you close your View you must switch back to the old view.
  2504.   (See examples for more details.)
  2505.  
  2506.   Synopsis: LoadView( view );
  2507.  
  2508.   view:     (struct View *) Pointer to the View.
  2509.  
  2510.  
  2511. FreeVPortCopLists()
  2512.  
  2513.   This function will return all memory that was automatically
  2514.   allocated by the MakeVPort() function. Remember to call
  2515.   FreeVPortCopLists() for every ViewPort you have created!
  2516.  
  2517.   Synopsis: FreeVPortCopLists( viewport );
  2518.  
  2519.   view:     (struct ViewPort *) Pointer to the ViewPort.
  2520.  
  2521.  
  2522. FreeCprList()
  2523.  
  2524.   This function will return all memory that was automatically
  2525.   allocated by the MrgCop() function.
  2526.  
  2527.   Synopsis: FreeCprList( cprlist );
  2528.  
  2529.   cprlist:  (struct cprlist *) Pointer to the View's cprlist
  2530.             (LOFCprList) structure. If the View was interlaced
  2531.             you must also call the FreeCprList function with a
  2532.             pointer to the SHFCprList.
  2533.  
  2534.  
  2535. FreeRaster()
  2536.  
  2537.   This function will deallocate display memory (BitPlane).
  2538.   Remember to deallocate all BitPlanes!
  2539.  
  2540.   Synopsis: FreeRaster( bitplane, width, height );
  2541.  
  2542.   bitplane: (PLANEPTR) Pointer to a Bitplane.
  2543.  
  2544.   width:    (long) The Bitplane's width.
  2545.  
  2546.   height:   (long) The Bitplane's height.
  2547.  
  2548.  
  2549. FreeColorMap()
  2550.  
  2551.   This function deallocates the memory that was allocated by
  2552.   the GetColorMap() function. Remember to deallocate all memory
  2553.   that you allocate. For every GetColorMap() function there
  2554.   should be one FreeColorMap() function.
  2555.  
  2556.   FreeColorMap( colormap );
  2557.  
  2558.   colormap: (struct ColorMap *) Pointer to a ColorMap structure
  2559.             that GetColorMap() returned and you now want to
  2560.             deallocate.
  2561.  
  2562.  
  2563. InitRastPort()
  2564.  
  2565.   This function initializes a RastPort.
  2566.  
  2567.   Synopsis:  InitRastPort( rast_port );
  2568.  
  2569.   rast_port: (RastPort *) Pointer to the RastPort that should
  2570.              be Initialized.
  2571.  
  2572.  
  2573. SetAPen()
  2574.  
  2575.   This function will change the FgPen's colour.
  2576.  
  2577.   Synopsis:   SetAPen( rast_port, new_colour );
  2578.  
  2579.   rast_port:  (struct RastPort *) Pointer to the RastPort that
  2580.               should be affected.
  2581.  
  2582.   new_colour: (long) A new colour value.
  2583.  
  2584.  
  2585. SetBPen()
  2586.  
  2587.   This function will change the BgPen's colour.
  2588.  
  2589.   Synopsis:   SetBPen( rast_port, new_colour );
  2590.  
  2591.   rast_port:  (struct RastPort *) Pointer to the RastPort that
  2592.               should be affected.
  2593.  
  2594.   new_colour: (long) A new colour value.
  2595.  
  2596.  
  2597. SetOPen()
  2598.  
  2599.   This macro will change the AOlPen's colour. Note! This is not
  2600.   a function. It is actually a macro that is defined in the
  2601.   header file "gfxmacros.h". If you want to use this function
  2602.   you have to remember to include this file.
  2603.  
  2604.   Synopsis:   SetOPen( rast_port, new_colour );
  2605.  
  2606.   rast_port:  (struct RastPort *) Pointer to the RastPort that
  2607.               should be affected.
  2608.  
  2609.   new_colour: (long) A new colour value.
  2610.  
  2611.  
  2612. SetDrMd()
  2613.  
  2614.   This function will change the drawing mode.
  2615.  
  2616.   Synopsis:  SetDrMd( rast_port, new_mode );
  2617.  
  2618.   rast_port: (struct RastPort *) Pointer to the RastPort that
  2619.              should be affected.
  2620.  
  2621.   new_mode:  (long) The new drawing mode. Set one of the
  2622.              following: JAM1, JAM2, COMPLEMENT, INVERSVID|JAM1
  2623.              or INVERSVID|JAM2.
  2624.  
  2625.              JAM1           The FgPen will be used, the
  2626.                             background unchanged. (One colour
  2627.                             jammed into a Raster.)
  2628.  
  2629.              JAM2           The FgPen will be used as foreground
  2630.                             pen while the background (when you
  2631.                             are writing text for example) will
  2632.                             be filled with the BgPen's colour.
  2633.                             (Two colours are jammed into a
  2634.                             Raster.)
  2635.  
  2636.              COMPLEMENT     Each pixel affected will be drawn
  2637.                             with the binary complement colour.
  2638.                             Where you write 1's the
  2639.                             corresponding bit in the Raster
  2640.                             will be reversed.
  2641.  
  2642.              INVERSVID|JAM1 This mode is only use together with
  2643.                             text. Only the background of the
  2644.                             text will be drawn with the FgPen.
  2645.  
  2646.              INVERSVID|JAM2 This mode is only use together with
  2647.                             text. The background of the text
  2648.                             will be drawn with the FgPen, and
  2649.                             the characters itself with the
  2650.                             BgPen.
  2651.  
  2652.  
  2653. SetDrPt()
  2654.  
  2655.   This function will set the line pattern.
  2656.  
  2657.   Synopsis:     SetDrPt( rast_port, line_pattern );
  2658.  
  2659.   rast_port:    (struct RastPort *) Pointer to the RastPort
  2660.                 that should be affected.
  2661.  
  2662.   line_pattern: (UWORD) The pattern. Each bit represents one
  2663.                 dot. To generate solid lines you set the
  2664.                 pattern value to 0xFFFF [hex] (1111111111111111
  2665.                 [bin]).
  2666.  
  2667.  
  2668. SetAfPt()
  2669.  
  2670.   This function will set the area pattern:
  2671.  
  2672.   Synopsis:     SetAfPt( rast_port, area_pattern, pow2 );
  2673.  
  2674.   rast_port:    (struct RastPort *) Pointer to the RastPort
  2675.                 that should be affected.
  2676.  
  2677.   area_pattern: (UWORD) Pointer to an array of UWORDS that
  2678.                 generate the pattern. Each bit in the array
  2679.                 represents one dot.
  2680.  
  2681.   pow2:         (BYTE) The pattern must be two to the power of
  2682.                 pow2 lines tall. If the pattern is one line tall
  2683.                  pow2 should be set to 0, if the pattern is two
  2684.                 lines tall pow2 should be set to 1, if the
  2685.                 pattern is four lines tall pow2 should be set to
  2686.                 2, and so on. (If you use multicoloured patterns
  2687.                 the pow2 should be negative. A sixteen lines
  2688.                 tall multicoloured pattern should therefore have
  2689.                 the pow2 value set to -4 [2^4 = 16].)
  2690.  
  2691.  
  2692. WritePixel()
  2693.  
  2694.   This function will draw a single pixel.
  2695.  
  2696.   Synopsis:  WritePixel( rast_port, x, y );
  2697.  
  2698.   rast_port: (struct RastPort *) Pointer to the RastPort that
  2699.              should be affected.
  2700.  
  2701.   x:         (long) X position of the pixel. 
  2702.  
  2703.   y:         (long) Y position of the pixel.
  2704.  
  2705.  
  2706. ReadPixel()
  2707.  
  2708.   This function reads the colour value of a pixel.
  2709.  
  2710.   Synopsis:  colour = ReadPixel( rast_port, x, y );
  2711.  
  2712.   colour:    (long) ReadPixel returns the colour value of the
  2713.              specified pixel (colour 0 - 255 ) or -1 if the
  2714.              coordinates were outside the Raster.
  2715.  
  2716.   rast_port: (struct RastPort *) Pointer to the RastPort which
  2717.              contain the pixel you want to examine.
  2718.  
  2719.   x:         (long) X position of the pixel. 
  2720.  
  2721.   y:         (long) Y position of the pixel.
  2722.  
  2723.  
  2724. Move()
  2725.  
  2726.   This function moves the cursor.
  2727.  
  2728.   Synopsis:  Move( rast_port, x, y );
  2729.  
  2730.   rast_port: (struct RastPort *) Pointer to the RastPort that
  2731.              should be affected.
  2732.  
  2733.   x:         (long) The new X position. 
  2734.  
  2735.   y:         (long) The new Y position.
  2736.  
  2737.  
  2738. Text()
  2739.  
  2740.   This function prints text into a Raster.
  2741.  
  2742.   Synopsis:  Text( rast_port, string, nr_of_chr );
  2743.  
  2744.   rast_port: (struct RastPort *) Pointer to the RastPort that
  2745.              should be affected.
  2746.  
  2747.   string:    (char *) Pointer to a text string that will be
  2748.              printed.
  2749.  
  2750.   nr_of_chr: (long) The number of characters that should be
  2751.              printed.
  2752.  
  2753.  
  2754. Draw()
  2755.  
  2756.   This function draws single lines from the current position
  2757.   to the new specified position.
  2758.  
  2759.   Synopsis:  Draw( rast_port, x, y );
  2760.  
  2761.   rast_port: (struct RastPort *) Pointer to the RastPort that
  2762.              should be affected.
  2763.  
  2764.   x:         (long) The new X position. 
  2765.  
  2766.   y:         (long) The new Y position.
  2767.  
  2768.  
  2769. PolyDraw()
  2770.  
  2771.   This function will draw multiple lines.
  2772.  
  2773.   Synopsis:    PolyDraw( rast_port, number, coordinates );
  2774.  
  2775.   rast_port:   (struct RastPort *) Pointer to the RastPort that
  2776.                should be affected.
  2777.  
  2778.   number:      (long) The number of coordinates (x,y) defined
  2779.                in the array.
  2780.  
  2781.   coordinates: (short *) Pointer to an array of coordinates.
  2782.  
  2783.  
  2784. RectFill()
  2785.  
  2786.   This function will draw filled rectangles.
  2787.  
  2788.   Synopsis:  RectFill( rast_port, minx, miny, maxx, maxy );
  2789.  
  2790.   rast_port: (struct RastPort *) Pointer to the RastPort that
  2791.              should be affected.
  2792.  
  2793.   minx:      (long) Left position of the rectangle.
  2794.  
  2795.   miny:      (long) Top          - " -
  2796.  
  2797.   maxx:      (long) Right        - " -
  2798.  
  2799.   maxy:      (long) Bottom       - " -
  2800.  
  2801.  
  2802. Flood()
  2803.  
  2804.   This function will flood fill complicated objects.
  2805.  
  2806.   Synopsis:  Flood( rast_port, mode, x, y ); 
  2807.  
  2808.   rast_port: (struct RastPort *) Pointer to the RastPort that
  2809.              should be affected.
  2810.  
  2811.   mode:      (long) Which mode should be used. If you want to
  2812.              use the Colour mode set the mode variable to 1, to
  2813.              get the Outline mode set the mode variable to 0.
  2814.  
  2815.   x:         (long) X position where the flood fill should
  2816.              start.
  2817.  
  2818.   y:         (long) Y position where the flood fill should
  2819.              start.
  2820.  
  2821.  
  2822. AreaMove()
  2823.  
  2824.   This function will start a new polygon.
  2825.  
  2826.   Synopsis:  AreaMove( rast_port, x, y );
  2827.  
  2828.   rast_port: (struct RastPort *) Pointer to the RastPort that
  2829.              should be affected.
  2830.  
  2831.   x:         (long) Start X position.
  2832.  
  2833.   y:         (long) Start Y position.
  2834.  
  2835.  
  2836. AreaDraw()
  2837.  
  2838.   This function will add a new vertex to the vector list. 
  2839.  
  2840.   Synopsis:  AreaDraw( rast_port, x, y );
  2841.  
  2842.   rast_port: (struct RastPort *) Pointer to the RastPort that
  2843.              should be affected.
  2844.  
  2845.   x:         (long) New X position.
  2846.  
  2847.   y:         (long) New Y position.
  2848.  
  2849.  
  2850. AreaEnd()
  2851.  
  2852.   This function will close, draw and fill the polygon.
  2853.  
  2854.   Synopsis:  AreaEnd( rast_port );
  2855.  
  2856.   rast_port: (struct RastPort *) Pointer to the RastPort that
  2857.              should be affected.
  2858.  
  2859.  
  2860. BNDROFF()
  2861.  
  2862.   This macro (declared in file "gfxmacro.h") will turn off the
  2863.   outline mode.
  2864.  
  2865.   Synopsis:  BNDROFF( rast_port );
  2866.  
  2867.   rast_port: Pointer to the RastPort which outlinefunction
  2868.              should be turned off.
  2869.  
  2870.  
  2871. SetRast()
  2872.  
  2873.   This function sets a whole Raster to a specific colour.
  2874.  
  2875.   Synopsis:  SetRast( rast_port, colour );
  2876.  
  2877.   rast_port: (struct RastPort *) Pointer to the RastPort that
  2878.              should be affected.
  2879.  
  2880.   colour:    (long) The colour reg. you want to fill the whole
  2881.              raster with.
  2882.  
  2883.  
  2884. ScrollRaster()
  2885.  
  2886.   This function will scroll a rectangular area of a raster.
  2887.  
  2888.   Synopsis:  ScrollRaster( rp, dx, dy, minx, miny, maxx, maxy );
  2889.  
  2890.   rp:        (struct RastPort *) Pointer to the RastPort that
  2891.              should be affected.
  2892.  
  2893.  
  2894.   dx:        (long) Delta X movement. (A positive number moves
  2895.              the area to the right, a negative number to the
  2896.              left.)
  2897.  
  2898.   dy:        (long) Delta Y movement. (A positive number moves
  2899.              the area down, a negative number up.)
  2900.  
  2901.   minx:      (long) Left edge of the rectangle.
  2902.  
  2903.   miny:      (long) Top edge of the rectangle.
  2904.  
  2905.   maxx:      (long) Right edge of the rectangle.
  2906.  
  2907.   maxy:      (long) Bottom edge of the rectangle.
  2908.  
  2909.  
  2910. BltBitMap()
  2911.  
  2912.   This function copies parts of BitMaps directly without
  2913.   worrying about overlapping layers.
  2914.  
  2915.   Synopsis: BltBitMap( sb, sx, sy, db, dx, dy, w, h, fl, m, t );
  2916.  
  2917.   sb:       (struct BitMap *) Pointer to the "source" BitMap.
  2918.  
  2919.   sx:       (long) X offset, source.
  2920.  
  2921.   sy:       (long) Y offset, source.
  2922.  
  2923.   db:       (struct BitMap *) Pointer to the "destination"
  2924.             BitMap.
  2925.  
  2926.   dx:       (long) X offset, destination.
  2927.  
  2928.   dy:       (long) Y offset, destination.
  2929.  
  2930.   w:        (long) The width of the memory area that should be
  2931.             copied.
  2932.  
  2933.   h:        (long) The height of the memory area that should be
  2934.             copied.
  2935.  
  2936.   fl:       (long) The four leftmost bits tells the blitter
  2937.             what kind of logically operations should be done.
  2938.  
  2939.   m:        (long) You can here define a BitMap mask, and tell
  2940.             the blitter which BitPlanes should be used, and
  2941.             which should not. The first bit represents the
  2942.             first BitPlane, the second bit the second BitPlane
  2943.             and so on. If the bit is on (1) the corresponding
  2944.             BitPlane will be used, else (0) the BitPlane will
  2945.             not be used. To turn off BitPlane zero and two, set
  2946.             the mask value to 0xFA (11111010). To use all
  2947.             BitPlanes set the mask value to 0xFF (11111111).
  2948.  
  2949.   t:        (char *) If the copy overlaps and this pointer
  2950.             points to some chip-memory, the memory will be used
  2951.             to store the temporary area in. However, normally
  2952.             you do not need to bother about this value.
  2953.  
  2954.  
  2955. ClipBlit()
  2956.  
  2957.   This function copies parts of BitMaps with help of Rastports
  2958.   and will therefore care about overlapping layers, and should
  2959.   be used if you have windows on your display.
  2960.  
  2961.   Synopsis: ClipBlit( srp, sx, sy, drp, dx, dy, w, h, flag );
  2962.  
  2963.   srp:      (struct RastPort *) Pointer to the "source"
  2964.             RastPort.
  2965.  
  2966.   sx:       (long) X offset, source.
  2967.  
  2968.   sy:       (long) Y offset, source.
  2969.  
  2970.   drp:      (struct RastPort *) Pointer to the "destination"
  2971.             RastPort.
  2972.  
  2973.   dx:       (long) X offset, destination.
  2974.  
  2975.   dy:       (long) Y offset, destination.
  2976.  
  2977.   w:        (long) The width of the memory area that should be
  2978.             copied.
  2979.  
  2980.   h:        (long) The height of the memory area that should be
  2981.             copied.
  2982.  
  2983.   flag:     (long) This value tells the blitter what kind of
  2984.             logically operations should be done. See below for
  2985.             more information.
  2986.  
  2987.  
  2988.  
  2989. 12.5  EXAMPLES
  2990.  
  2991. Example1
  2992.   This example shows how to create your own display, and fill
  2993.   it with a lot of pixels in seven different colours.
  2994.  
  2995. Example2
  2996.   This example shows how to create a large Raster and a smaller
  2997.   display. We fill the Raster with a lot of pixels in seven
  2998.   different colours and by altering the RxOffset and RyOffset
  2999.   values in the RasInfo structure, the Raster is scrolled in
  3000.   all directions. This method to scroll a large drawing in full
  3001.   speed is used in many games and was even used in my own
  3002.   racing game "Car".
  3003.  
  3004. Example3
  3005.   This example shows how to create a display that covers the
  3006.   entire display. This method is called "Overscan", and is
  3007.   primarily used in video and graphics programs, but can also
  3008.   be used in games etc to make the display more interesting.
  3009.  
  3010. Example4
  3011.   This example demonstrates how to open two different ViewPorts
  3012.   on the same display. The first ViewPort is in low resolution
  3013.   and use 32 colours, while the second ViewPort is in high
  3014.   resolution and only use 2 colours.
  3015.  
  3016. Example5
  3017.   This example demonstrates how to open a ViewPort in interlace
  3018.   mode.
  3019.  
  3020. Example6
  3021.   This example demonstrates how to create a ViewPort in dual
  3022.   playfield mode. Playfield 1 use four colours and is placed
  3023.   behind playfield 2 which only use two colours (transparent
  3024.   and grey). Playfield 1 is filled with a lot of dots and is
  3025.   scrolled around while playfield 2 is is not moved and is
  3026.   filled with only five grey rectangles.
  3027.  
  3028. Example7
  3029.   This example demonstrates how to create a ViewPort with the
  3030.   special display mode "Hold and Modify".
  3031.  
  3032. Example8
  3033.   This example shows how to use the functions: SetAPen(),
  3034.   SetBPen(), SetOPen(), SetDrMd(), SetDrPt(), WritePixel(),
  3035.   ReadPixel(), Move(), Draw(), Text() and finally PolyDraw().
  3036.  
  3037. Example9
  3038.   This example shows how to flood fill a figure, and how to
  3039.   draw filled rectangles (both solid as well as filled with
  3040.   single and multi coloured patterns).
  3041.  
  3042. Example10
  3043.   This example demonstrate how to use the Area Fill functions.
  3044.   [ AreaMove(), AreaDraw() and AreaEnd(). ]
  3045.  
  3046. Example11
  3047.   This example demonstrate how to copy rectangular memory areas
  3048.   with help of the blitter. 
  3049.